Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it normal for saveXML() to insert whitespace characters?

Status
Not open for further replies.

stebboko

Technical User
Jul 16, 2007
4
AU
Using the typical DOMDocument way of creating of XML output (createElement, appendChild etc) via PHP, then dumping with echo $doc->saveXML();

The receiving XML parser (AJAX) doesn't like it. If I tell it to use a static XML file that I create by removing the \n and \r's, all is well.

ie. I strip
...<item>13</item>\n <item>15</item>\n...
to become
...<item>13</item><item>15</item>...

Surely saveXML() would be outputing valid XML. Is it some sort of Windows thing?




 
>The receiving XML parser (AJAX) doesn't like it.
In what sense "the receiving XML parser (AJ**) doesn't like it. I must say on the face of it, I don't like it neither. "\n" is a character entity recognized by php, but on it's own, xml would take it as backslash and character n, and not recognize it as a whitespace.
 
I tried about 50 different things and what worked was a combination of setting the DOMDocument's formatOutput property to false and setting a header('Content-type: text/xml; charset=utf-8')

Frustrating...
 
Frustrating be it, to get anything work, it goes without saying all the settings must be observed. Sure. But if the \n is inserted by dom methods, it must be done properly. For instance,
[tt] $x=$doc->createTextNode("\n");[/tt]
is one of the ways... and then get it inserted at the proper places.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top