PTH PHP XPath to XML file lookup and modify implementation code

Source: Internet
Author: User
Tags xpath
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.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.