PhpXPath can find and modify the implementation code of the XML file. For more information, see.
The code is as follows:
/*
11
Content1
2009-10-11
Title2
Content2
*/
If (! Function_exists ('L ')){
Function l (){
Echo'
***********************************
';
}
}
If (file_exists ('test10 _ 12. XML ')){
$ Xml = simplexml_load_file ('test10 _ 12. XML ');
// Use the xpath method to find the node location
$ Query = $ xml-> xpath ('// title [@ name = "t1"]/ancestor: item ');
Var_dump ($ query );
L ();
// Test the addition of a subnode new under the title node
$ Query [0]-> title-> addChild ('new', 'new ');
// Test the function of adding a property fuck to the title node.
$ Query [0]-> title-> addAttribute ('fuck', 'fuck ');
// Test and modify the content node value to hello, world
$ Query [0]-> content = 'Hello, world ';
// Do not explain, you know
$ Query [0]-> asXML ("10.xml ");
}
?>