我试图访问xml元素的文本值.我在用SimpleXMLElement.我必须遗漏一些明显的东西.
<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);
Run Code Online (Sandbox Code Playgroud)
运行上面的代码给了我:
array (
0 =>
SimpleXMLElement::__set_state(array(
0 => 'NewForm',
)),
)
Run Code Online (Sandbox Code Playgroud)
看起来很简单.我很难获得'NewForm'的价值
我试过了
$result[0],$result[0]->{0},$result[0][0].
通过孩子的迭代$result[0].
有人可以帮助指导我正确的方向,以便我可以从标题元素获取文本?