Jump to content

Writing XML


ameliabob

Recommended Posts

I have an existing document on the server and will be updating the file based on the browser and would like to write it back to disk upon completion.I am using the "xmlDoc.load("note.xml");" that is in your example but I can't find the corresponding output statement. Where would I find this?

Link to comment
Share on other sites

You can't write in an XML document with Javascript. You can modify the nodes before you use them for something, that's all.If you use PHP's DOMDocument you can use file_put_contents() and put the XML in the file after processing it (I've used it myself for RSS feeds).

Link to comment
Share on other sites

I have an existing document on the server and will be updating the file based on the browser and would like to write it back to disk upon completion.I am using the "xmlDoc.load("note.xml");" that is in your example but I can't find the corresponding output statement. Where would I find this?
So, if I understand you correctly, I load an XML document then if I process it and change some values I use the file_put_content. But do I just point to the DOM object to put it out?
Link to comment
Share on other sites

You use the saveXML() method of the DOMDocument object to convert the XML to a string and then put it back into the file you extracted it from.Well, you do it like this:

$xmlDoc = new DOMDocument();$xmlDoc->load("file.xml");// Perform some XML DOM modificationsfile_put_contents("file.xml",$xmlDoc->saveXML());

Link to comment
Share on other sites

Note that a more efficient alternative is to use DOMDocument::save(), like:

$xmlDoc = new DOMDocument();$xmlDoc->load("file.xml");// Perform some XML DOM modifications$xmlDoc->save('file.xml');

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...