Say I have this following XML structure:
some value<
Variant for xpath (Also how to get content of node having dashes in name):
<?xml version="1.0" encoding="UTF-8"?> <main> <parent> <child-1>some value</child-1> <child-2>another value</child-2> </parent> </main>
$xml = simplexml_load_string($content);
$node_value= (string)$xml->xpath('parent/child-1')[0];
result of $node_value:
"some value"
$xml = new SimpleXMLElement($xml);
$this->xmlcode = (string) $xml->parent[0]->child1;
A good example of using XPath with php for the SimpleXMLElement can be found here http://www.php.net/manual/en/class.simplexmlelement.php#95229
// Find the topmost element of the domDocument
$xpath = new DOMXPath($xml);
$child1 = $xpath->evaluate('/main/parent/child1')->item(0);