This may be simple but I couldn't find any example on the web. I need to find a node using xpath and replace it's value.
This is a small version of the xml document:
<?xml version="1.0" encoding="utf-16" standalone="yes"?> <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:body> </w:p> <w:r> <w:t>John Doe</w:t> </w:r> </w:p> </w:body> </w:document>
And this is my php code:
<?php $xml = simplexml_load_file("doc1/word/document.xml"); $result = $xml->xpath("/w:document/w:body/w:p/w:r/w:t"); // the following code doesn't work... $xml->$result = "George Dow"; echo $xml->asXML(); ?>
Basically, John Doe should be George Dow
I found the solution. Basically, since the xpath function returns
a SimpleXMLElement Object an array, I need to access it as one:
// the following code doesn't work... $xml->$result = "George Dow"; // but this does :D $result = "George Dow";
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki