从解析的 XML 中读取数据
我有一个由 API 返回的 XML 文件。我想从中获取特定数据。我已通过 $xml = simpleXMLToArray(simplexml_load_string($response));
将 XML 转换为数组 $response 是 XML。$xml 是包含所有 XML 数据的数组。我想从中提取数据,但它不起作用。
foreach($xml['conetent']['album']['media'] as $media)
{
//var_dump($media);
echo $media;
}
I have an XML file that is returned by an API.i want to get specfic Data out of it.I had converted the XML into array by $xml = simpleXMLToArray(simplexml_load_string($response));
$response is the XML.$xml is the array that have all the XML data.I want to extract data out of it but its not working.
foreach($xml['conetent']['album']['media'] as $media)
{
//var_dump($media);
echo $media;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦您将“conetent”的拼写更正为“content”,它在这里就可以正常工作
编辑:
因此,根据您的问题的更新,这样怎么样:
It works fine here once you correct the spelling of 'conetent' to 'content'
Edit:
So with the update from your question, how about this:
看起来您有两个级别的专辑标签。不使用 simpleXMLToArray() 可能会更容易,而只需使用 xpath:
It would appear you have two levels of album tags. It would probably be easier not to use simpleXMLToArray() but just search for your media with xpath: