Copy codeThe Code is as follows:
<? Php
/*
<? Xml version = "1.0" encoding = "UTF-8"?>
<Article>
<Item>
<Title name = "t1"> 11 </title>
<Content> content1 </content>
<Pubdate> 2009-10-11 </pubdate>
</Item>
<Item>
<Title name = "t2"> title2 </title>
<Content> content2 </content>
<Pubdate> 2009-11-11 </pubdate>
</Item>
</Article>
*/
If (! Function_exists ('l ')){
Function l (){
Echo '<br/> ********************************** * <br/> ';
}
}
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 ");
}
?>