php - 用php循环遍历xml,无法在同一个数组中获取图像:标题和url
问题描述
我只是想遍历这个 xml 并回显每个我已经能够单独执行的对象,但希望每个对象都在 foreach 中
$xml = new SimpleXMLElement($response);
foreach ($xml->url as $url_list)
{
$url = $url_list->loc;
echo $url; //works
$image_title = $url_list->image:title;
echo $image_title; ///doesn't work
//would also like to get other 4 objects lastmod,changefreq,image:loc
}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>https://example.com/collections/xxx</loc>
<lastmod>2021-02-04T17:35:40-05:00</lastmod>
<changefreq>daily</changefreq>
<image:image>
<image:loc>https://example.com/collections/xxx.png?v=1582857057</image:loc>
<image:title>xxx</image:title>
</image:image>
</url>
<url>
<loc>https://example.com/collections/yyy</loc>
<lastmod>2021-02-04T22:50:40-05:00</lastmod>
<changefreq>daily</changefreq>
<image:image>
<image:loc>https://example.com/collections/yyy.png?v=1582858125</image:loc>
<image:title>yyy</image:title>
</image:image>
</url>
解决方案
推荐阅读
- camera - Filepond:如何允许相机输入
- hibernate - Simbol p:在句子中用弹簧休眠
- reactjs - 反应路由器默认路由不适用于嵌套结构
- php - Laravel 请求总是返回 null
- reactjs - 在反应中从外部功能组件调用函数
- scala - Spark RDD双重比较错误:值>不是(Double,Double)的成员
- sql - 如何在 SQLite(或 Oracle)中编写根据日期间隔选择数据的查询函数?
- javascript - 来自我的本地主机的 Nodejs 表单响应错误
- laravel - Guzzle 请求未返回完整响应
- discord - 调用任何命令时运行另一个函数 discord.py