I have example.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">
<content>
<books>
<book>
<qty>12</qty>
<title>C++</title>
</book>
<book>
<qty>21</qty>
<title>PHP</title>
</book>
</books>
</content>
&开发者_JAVA百科lt;/Document>
Currently I did like (with file)
$xmlFile = file_get_contents("example.xml");
$xml = str_replace('<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02"> ', "<Document>", $xmlFile); // This removes ALL default namespaces.
//echo $xmlFile;
$fp = fopen('example.xml', 'w');
fwrite($fp, $xml);
fclose($fp);
//TODO MORE AFTER IT
Are there other way(Remove the xmlns) to it with DOMDOcument? Because I am using read/write file.
I've never tried this but based on the docs, this might work:
<?php
$dom = new DOMDocument();
$dom->load('example.xml');
$dom->documentElement->removeAttribute("xmlns");
echo $dom->saveXML();
?>
Not a very clean solution, but it might work if you are really just trying to get rid of the xmlns attribute.
精彩评论