Copy Code code 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 ');
Finding node locations with XPath methods
$query = $xml->xpath ('//title[@name = ' T1 ']/ancestor::item ');
Var_dump ($query);
L ();
Test new child node new under Title node
$query [0]->title->addchild (' New ', ' new ');
To test new properties under the title node fuck
$query [0]->title->addattribute (' Fuck ', ' fuck you ');
Test modify Content node value is Hello,world
$query [0]->content = ' Hello,world ';
Don't explain, you know.
$query [0]->asxml ("10.xml");
}
?>