说我有这个下面的XML结构:的SimpleXML获取节点值
<?xml version="1.0" encoding="UTF-8"?>
<main>
<parent>
<child1>some value</child1>
<child2>another value</child2>
</parent>
</main>
我做了XML的一个变量,现在我想child1的价值,所以我使用的SimpleXML:
$xml = new SimpleXMLElement($xml);
$this->xmlcode = (string) $xml->main->parent->child1;
但是我收到这条消息:注意:试图在/x.php上获取非对象的属性x
我也试过用$ xml-> parent-> child1,但没有成功。
任何??
发现*叹*这必须是最常见的错误有史以来之一。将XML文档加载到SimpleXmlElement中时,根节点是SimpleXmlElement,例如, '$ xml ='。 –
Gordon
2011-04-08 10:35:27
感谢Gordon的解释。 – priktop 2011-04-08 10:37:29