从网站 xml 解析器 php 解析 xml id
我想解析以下 id:date
我将如何选择它?我知道如何选择班级,但我没有找到 id。
这就是我对类所做的:
$xml->xpath('//*[@class="date"]');
我尝试将 @class
切换为 @id
但没有运气。我做错了什么?
先感谢您
@$doc=new DOMDocument();
@$doc->loadHTML($html5);
$xml=simplexml_import_dom($doc);
$images=$xml->xpath('//*[@id="date"]');
$arr= array();
foreach ($images as $img) {
$arr[]= $img;
}
echo $arr[0];
I would like to parse the following id: date
How would I select it? I know how to select a class but I have had no luck for an id.
This is what I did with classes:
$xml->xpath('//*[@class="date"]');
I tried switching @class
for @id
but no luck. What am I doing wrong?
Thank you in advance
@$doc=new DOMDocument();
@$doc->loadHTML($html5);
$xml=simplexml_import_dom($doc);
$images=$xml->xpath('//*[@id="date"]');
$arr= array();
foreach ($images as $img) {
$arr[]= $img;
}
echo $arr[0];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然你让我感觉很糟糕...
下面的 xpath 查询将检索具有属性 id = date 的所有元素。由于您只关心第一个(不应该超过一个,因为 ID 属性应该是唯一的......但您永远不知道),因此您需要在中引用
item(0)
xpath 查询返回的DOMNodeList
。希望有帮助。
Now that you made me feel bad ...
The xpath query below will retrieve all elements that have the attribute id = date. Since you only care about the first one (there shouldn't be more than one because ID attributes are supposed to be unique ... but you never know), you need to reference
item(0)
in theDOMNodeList
returned by the xpath query.Hope that helps.