参见英文答案 >
Accessing certain properties of a SimpleXMLElement Object 1个
我试图访问xml元素的文本值.我正在使用SimpleXMLElement.我必须遗漏一些明显的东西.
我试图访问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);
运行上面的代码给了我:
array ( 0 => SimpleXMLElement::__set_state(array( 0 => 'NewForm',)),)
看起来很简单.我很难获得’NewForm’的价值
我试过了
$result [0],$result [0] – > {0},$result [0] [0].
迭代$result的子项[0].
解决方法
这对我的例子很有用:
echo (string)$result[0];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。