PhpXPath implements code for searching and modifying XML files
Source: Internet
Author: User
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 ");
}
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.