假设我有以下 XML 结构:
<?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 行的/x.php 中获取非对象的属性
我也用 $xml->parent->child1 试过,但没有成功。
有人吗?
最佳答案
$xml = new SimpleXMLElement($xml);
$this->xmlcode = (string) $xml->parent[0]->child1;
关于php - SimpleXML 获取节点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5593554/