I am trying to import XML from one document to another. This generally works fine, as demonstrated:
The output is good:PHP Code:<?php
header("Content-Type: application/xml");
$xml1 = "<beer><guiness>yum</guiness></beer>";
$xml2 = "<franziskaner><div>delicious</div></franziskaner>";
$doc1 = new DOMDocument();
$doc1->loadXML($xml1);
$doc2 = new DOMDocument();
$doc2->loadXML($xml2);
$doc1->documentElement->appendChild($doc1->importNode($doc2->documentElement,TRUE));
die($doc1->saveXML());
?>
The problem begins when the imported XML has a node with an xmlns attribute:Code:<beer> <guiness>yum</guiness> <franziskaner> <div>delicious</div> </franziskaner> </beer>
What happens to the output in this case, is all HTML nodes are then prefixed with "default":PHP Code:$xml2 = "<franziskaner><div xmlns=\"http://www.w3.org/1999/xhtml\">delicious</div></franziskaner>";
How can I import the XML "as is" without the "default" prefix?Code:<beer> <guiness>yum</guiness> <franziskaner xmlns:default="http://www.w3.org/1999/xhtml"> <default:div xmlns="http://www.w3.org/1999/xhtml">delicious</default:div> </franziskaner> </beer>
Thanks
Aaron
I believe this is specific to PHP, as I tested the same code in C# with no issues.


Reply With Quote
