I am trying to access the text value of a xml element. I am using SimpleXMLElement. I have to be missing something obvious.
<h:html xmlns:jr="http://openrosa.org/javarosa" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>NewForm</h:title>
</h:head>
</h:html>
$xml = new SimpleXMLElement($resp);
$xml->registerXPathNamespace('h', 'http://www.w3.org/1999/xhtml');
// I have tried with and without the namespace (it doesn't seem to make a difference)
$result = $xml->xpath('//h:title');
debug($result);
Running the code above gives me:
array (
0 =>
SimpleXMLElement::__set_state(array(
0 => 'NewForm',
)),
)
Seems very simple. I am having difficulty getting the value of the ‘NewForm’
I have tried
$result[0], $result[0]->{0}, $result[0][0].
Iterating through the children of the $result[0].
Could someone please help guide me in the correct direction so I can get the text from the title element?
This worked for me with your example: