Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从xml文件中删除名称空间并另存为新xml_Php_Xml_Namespaces - Fatal编程技术网

Php 从xml文件中删除名称空间并另存为新xml

Php 从xml文件中删除名称空间并另存为新xml,php,xml,namespaces,Php,Xml,Namespaces,这是我获取XML文件的链接:- 这是我的代码:- <?php function convertNodeValueChars($node) { if ($node->hasChildNodes()) { foreach ($node->childNodes as $childNode) { if ($childNode->nodeType == XML_TEXT_NODE) { $childNode->nodeV

这是我获取XML文件的链接:-

这是我的代码:-

<?php
function convertNodeValueChars($node) {
    if ($node->hasChildNodes()) {
      foreach ($node->childNodes as $childNode) {
        if ($childNode->nodeType == XML_TEXT_NODE) {
          $childNode->nodeValue = iconv('utf-8', 'ascii//TRANSLIT', $childNode->nodeValue);
        }
        convertNodeValueChars($childNode);         
      }
    }      
  } 

  $doc = new DOMDocument();
  $doc->load('http://services.gisgraphy.com/geoloc/search?lat=13o6&lng=80o12&radius=7000');
  convertNodeValueChars($doc->documentElement);
  $doc->save('general.xml');  
?>
nodeValue=iconv('utf-8','ascii//translatit',$childNode->nodeValue);
}
convertNodeValueChars($childNode);
}
}      
} 
$doc=新的DOMDocument();
$doc->load($doc)http://services.gisgraphy.com/geoloc/search?lat=13o6&lng=80o12&radius=7000');
convertNodeValueChars($doc->documentElement);
$doc->save('general.xml');
?>
1) 我正在尝试将ASCII字符删除为普通字符
2) 要删除XML文件的名称空间这是包含名称空间的文件


3) 要另存为另一个XML文件

请首先在简单php文件上创建以从URL加载XML:-

<?php
$dom = new DOMDocument();
$dom->load('http://services.gisgraphy.com/geoloc/search?lat=22.298569900000000000&lng=70.794301799999970000&radius=7000', true);
$dom->save('filename.xml');
?>

然后创建一个XSLT文件:-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" encoding="UTF-8" />
        <xsl:template match="*">
                <xsl:element name="{local-name()}">
                        <xsl:apply-templates select="@* | node()"/>
                </xsl:element>
        </xsl:template>
</xsl:stylesheet>

并创建一个php文件以加载xml文件并实现我们的xslt文件:-

<?php
$sourcedoc->load('filename.xml');
    $stylesheet = new DOMDocument();
    $stylesheet->load('new4convert.xsl');
     // create a new XSLT processor and load the stylesheet
    $xsltprocessor = new XSLTProcessor();
    $xsltprocessor->importStylesheet($stylesheet);

    // save the new xml file
    file_put_contents('filename.xml', $xsltprocessor->transformToXML($sourcedoc));
?>
load('new4convert.xsl');
//创建新的XSLT处理器并加载样式表
$xsltprocessor=新的xsltprocessor();
$xsltprocessor->importStylesheet($stylesheet);
//保存新的xml文件
文件内容('filename.xml',$xsltprocessor->transformToXML($sourcedoc));
?>
如果要在一个PHP文件中保存所有内容,请使用最终总代码:-

<?php
$dom = new DOMDocument();
$dom->load('http://services.gisgraphy.com/geoloc/search?lat=22.298569900000000000&lng=70.794301799999970000&radius=7000', true);
$dom->save('filename.xml');
$sourcedoc = new DOMDocument();
    $sourcedoc->load('filename.xml');
    $stylesheet = new DOMDocument();
    $stylesheet->load('new4convert.xsl');
     // create a new XSLT processor and load the stylesheet
    $xsltprocessor = new XSLTProcessor();
    $xsltprocessor->importStylesheet($stylesheet);

    // save the new xml file
    file_put_contents('filename.xml', $xsltprocessor->transformToXML($sourcedoc));
?>
load('filename.xml');
$stylesheet=newdomdocument();
$stylesheet->load('new4convert.xsl');
//创建新的XSLT处理器并加载样式表
$xsltprocessor=新的xsltprocessor();
$xsltprocessor->importStylesheet($stylesheet);
//保存新的xml文件
文件内容('filename.xml',$xsltprocessor->transformToXML($sourcedoc));
?>

这个答案符合您的需要:@Tomalak不,这没有帮助。我想使用phpThere删除PHP中的XSLT支持。要使它正常工作,您需要花费大约10行代码。