使用php从多个子xml数据中获取所有值
我从xml数据中获取值时遇到问题,下面是我的数据使用php从多个子xml数据中获取所有值,php,xml,Php,Xml,我从xml数据中获取值时遇到问题,下面是我的数据 [a] => SimpleXMLElement Object ( [b] => SimpleXMLElement Object ( [id] => 123
[a] => SimpleXMLElement Object
(
[b] => SimpleXMLElement Object
(
[id] => 123
[name] => Daughter
[a] => SimpleXMLElement Object
(
[b] => SimpleXMLElement Object
(
[id] => 234
[name] => Mom
[c] => 1
[a] => SimpleXMLElement Object
(
[b] => SimpleXMLElement Object
(
[id] => 345
[name] => Grandma
)
)
)
)
)
)
如何获取这些数据
123女儿
妈妈
奶奶
该子项不只是3级,请尝试阅读此项,但仍然无法理解,任何人都可以帮助我,谢谢您您需要使用:
或者,如果您想打印姓名:
$xml = simplexml_load_string($xml);
foreach ($xml->xpath('//name') as $name) {
echo $name . PHP_EOL;
}
代码段:
$xml = simplexml_load_string($xml);
foreach ($xml->xpath('//name') as $name) {
echo $name . PHP_EOL;
}