开发者

Are there other way(xmlns) to it with DOMDOcument?

开发者 https://www.devze.com 2023-01-31 22:07 出处:网络
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\">

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消