如何循环 SimpleXML 对象?
我下载一个带有XML代码的网页:
$xml = simplexml_load_file($page);
结果是:
SimpleXMLElement Object
(
[@attributes] => Array
(
[Message] => Success
[Date] => 0001-01-01T00:00:00
)
[FUNDAMENTALS] => SimpleXMLElement Object
(
[FUNDAMENTAL] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Symbol] => AAA
[Name] => Description AAA
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Symbol] => BBB
[Name] => Description BBB
)
)
)
)
)
我必须读取每个[符号] [名称],我该怎么办?
I download a webpage with a XML code:
$xml = simplexml_load_file($page);
The results are:
SimpleXMLElement Object
(
[@attributes] => Array
(
[Message] => Success
[Date] => 0001-01-01T00:00:00
)
[FUNDAMENTALS] => SimpleXMLElement Object
(
[FUNDAMENTAL] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Symbol] => AAA
[Name] => Description AAA
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Symbol] => BBB
[Name] => Description BBB
)
)
)
)
)
I have to read each [Symbol] [Name], how can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西:
something like this:
您还可以使用
SimpleXmlIterator
:如果您只想迭代
元素,您可能需要考虑使用 XPath 获取它们,例如,如果您为您的问题提供一些 XML,我将为您提供一个代码示例。
You can also use the
SimpleXmlIterator
:If you only want to iterate over the
<FUNDAMENTAL>
elements, you might want to consider fetching them with an XPath, e.g.If you provide some XML to your question, I will provide you with a code example.