Jump to content

php XML DOM converts < and > to < and &qt; when assigning nodeValue


letoii

Recommended Posts

I am trying to assign a text value to an XML node.

 

$Data->nodeValue = '<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:'.$URN_UUID_ATTACHMENT.'" />'

 

The resulting xml is:

<Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:1294192877" /></Data>

 

is there a way to generate this instead:

<Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:1294192877" /></Data>

to the best of my knowledge, that xml is formatted correctly using html encoding. instead of modifying the xml to make it non-standard, i suggest that you modify the code that reads the xml <Data> element to un-format the html encoding as needed.

i suggest that you modify the code that reads the xml <Data> element to un-format the html encoding as needed.

The code that reads the XML is this:

 

$doc = new DOMDocument();
$doc->load('../../_xml/callxml/uploadFile.xml');

$DataNodes = $doc->getElementsByTagName('Data');
$Data = $DataNodes->item(0);

 

Where should the formatting be altered?

OK, I see my mistake. xop:include is actually a node. I can't write it in like regular text.

 

Correct way to do this is:

 

$xop = new DOMElement("xop:Include","","http://www.w3.org/2004/08/xop/include");
$xopNode = $Data->appendChild($xop);
$xopNode->setAttribute("href","cid:".$URN_UUID_ATTACHMENT);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.