11 content1 2009-10-1"/>
11 content1 2009-10-1">

Home  >  Article  >  Backend Development  >  pth php XPath implementation code for searching and modifying XML files

pth php XPath implementation code for searching and modifying XML files

WBOY
WBOYOriginal
2016-07-29 08:46:161277browse

Copy code The code is as follows:


/*



11
content1
2009-10-11

title2
content2
2009-11-11

< /article>
*/
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 new sub-node under title node new
$query[0]->title->addChild('new','new');
//Test under Add attribute fuck under the title node
$query[0]->title->addAttribute('fuck','fuck you');
//Test and modify the content node value to hello,world
$query[0] ->content = 'hello,world';
//No explanation, you know
$query[0]->asXML("10.xml");
}
?>

The above introduces the pth php XPath implementation code for XML file search and modification, including pth content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn