我是用PHP與XML一起工作的新手。我有一個相當複雜的XML結構,並且在laravel中使用simplexml,並且無法訪問我需要獲取的所有元素。我能夠遍歷大型的XML文件,但simpleXML每個記錄返回兩個對象,我似乎只能訪問'標題'中的元素,第一個對象返回...在Simplexml中訪問複雜結構中的元素
這裏是部分XML對象
SimpleXMLElement Object
(
[identifier] => RCM0635
[datestamp] => 2015-06-09
)
SimpleXMLElement Object
(
[lidoWrap] => SimpleXMLElement Object
(
[lido] => SimpleXMLElement Object
(
[lidoRecID] => RCM:1748
[descriptiveMetadata] => SimpleXMLElement Object
(
[objectClassificationWrap] => SimpleXMLElement Object
(
[objectWorkTypeWrap] => SimpleXMLElement Object
(
[objectWorkType] => SimpleXMLElement Object
(
[term] => musical instruments
)
)
[classificationWrap] => SimpleXMLElement Object
(
[classification] => Array
(
[0] => SimpleXMLElement Object
(
[term] => Cornet
)
[1] => SimpleXMLElement Object
(
[conceptID] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => SH_Class
)
)
)
)
)
)
有了下面的代碼,我可以得到頭中的元素,但我無法弄清楚如何獲得其他元素?
$streamer = \Prewk\XmlStringStreamer::createStringWalkerParser(public_path().'/xml/many_mimo_records.xml');
while ($node = $streamer->getNode()) {
$simpleXmlNode = simplexml_load_string($node);
echo (string)$simpleXmlNode->identifier;
echo (string)$simpleXmlNode->datestamp;
}
我會爲任何建議非常感謝......