Copy CodeThe code is as follows:
/*
11
Content1
2009-10-11
Title2
Content2
2009-11-11
*/
if (!function_exists (' l ')) {
function L () {
Echo '
***********************************
';
}
}
if (file_exists (' Test10_12.xml ')) {
$xml = simplexml_load_file (' Test10_12.xml ');
Finding node locations using the XPath method
$query = $xml->xpath ('//title[@name = "T1"]/ancestor::item ');
Var_dump ($query);
L ();
Test new child node under the title node new
$query [0]->title->addchild (' New ', ' new ');
The test adds a property under the title node fuck
$query [0]->title->addattribute (' Fuck ', ' fuck you ');
Test modify Content node value to Hello,world
$query [0]->content = ' Hello,world ';
No explanation, you know.
$query [0]->asxml ("10.xml");
}
?>
The above describes the PTH PHP XPath to the XML file to find and modify the implementation code, including the PTH content, I hope the PHP tutorial interested in a friend helpful.