XPATH - 选择具有特定属性的所有子节点 [英] XPATH - Select all child nodes with a specific attribute

查看:60
本文介绍了XPATH - 选择具有特定属性的所有子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查找具有特定属性值的所有子节点但从具有特定属性值的节点开始的 xpath 查询是什么?

What would be the xpath query to find all child nodes with a specific attribute value, but starting from a node with a specific attribute value?

这与我之前发布的有关解析 rdf xml 文件的问题有关 - 我以为我已经解决了,但还没有完全解决.

This is kind of related to a question I posted earlier about parsing an rdf xml file - I thought I had solved it but not quite yet.

例如,我试图解析和获取所有 rdf:about 属性值.我有这个工作正常.不过,我需要添加以下条件 - 需要在找到特定的 rdf:about 值后开始解析.

For example, I am trying to parse and grab all of the rdf:about attribute values. I have this working fine. I need to add the following condition though - parsing needs to start after a specific rdf:about value is found.

我正在使用 PHP 并使用 DomDocument 并使用以下 xpath 查询:

I am working in PHP and and using DomDocument and am using the following xpath query:

$xpath->query('//@rdf:about');

它发现所有 rdf:about 属性都很好.

It is finding all rdf:about attributes fine.

我需要扩展它以只找到那些 rdf:about 属性等于某值的节点之后的那些属性.

I need to extend this to only find those attributes that come after the node whose rdf:about attribute is equal to something.

希望这是有道理的.

推荐答案

$xpath->query("//*[@rdf:about='http://rdfs.org/sioc/ns#']/following-sibling::*/@rdf:about");

使用您的示例脚本,输出以以下开头/结尾的 URL:

With your sample script, outputs URLs starting/ending with:

http://rdfs.org/sioc/ns#Community
http://rdfs.org/sioc/ns#Container
...
http://rdfs.org/sioc/ns#reference
http://rdfs.org/sioc/ns#subject

这篇关于XPATH - 选择具有特定属性的所有子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆