Simplest XML Node Editor for PHP
Could someone please provide the simplest/shortest code that can edit the values within an xml node? I have been searching this for hours and all that I get are errors and failures. I need something that can get the node (/node/node1/node2) and edit the contents within it. I am using php-5. Thanks
Edit: Lets say I have this xml file:
<node>
<node2>
Content
</node2>
</node>
What I need t开发者_运维问答o do is change the value of <node2>
from "content"
to something else.
SimpleXML
$doc = simplexml_load_file('http://example.com/example.xml');
// Note the SimpleXMLElement is the root node, ie <node>
$doc->node2 = 'new content';
$doc->asXml('new-filename.xml'); // Note, saves locally
// or
$xmlString = $doc->asXml();
You are looking for SimpleXML, great class for XML parsing/editing
精彩评论