在 R 中使用 getNodeSet 进行复杂的 xPath 查询 [英] Complex xPath query with getNodeSet in R

查看:34
本文介绍了在 R 中使用 getNodeSet 进行复杂的 xPath 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Uniprot 蛋白质数据库下载了以下 xml 文件.

I have the following xml file downloaded from Uniprot protein database.

protein <- xmlRoot(xmlTreeParse("http://www.uniprot.org/uniprot/Q01974.xml"))

从众多注释特征中,我对存储在以下xml节点中的激酶域的开始和结束位置感兴趣:

From the numerous annotated features, I am interested in the start and end position of the kinase domain stored in the following xml node:

<feature type="domain" description="Protein kinase">
<location>
<begin position="288"/>
<end position="539"/>
</location>
</feature>

使用 getNodeSet 我可以很好地找到这个标签:

With the getNodeSet I could nicely locate this tag:

getNodeSet(protein, "//uniprot:feature[@type=\"domain\" and @description=\"Protein kinase\"]", c(uniprot="http://uniprot.org/uniprot"))

不幸的是,我无法缩小查询范围,添加任何其他条件都会返回一个空列表.示例:

Unfortunately I could not narrow down the query, addition of any other criteria returns an empty list. Example:

getNodeSet(protein, "//uniprot:feature[@type=\"domain\" and @description=\"Protein kinase\"]/location", c(uniprot="http://uniprot.org/uniprot"))

基于在线 xpath 测试器,这应该是有效的 xpath 查询,但返回空:

Based on an online xpath tester, that should be valid xpath query, but returns empty:

list()
attr(,"class")
[1] "XMLNodeSet"

有人可以帮我查询这个问题吗?我确信这是 getNodeSet 的正常行为,但我不知道它背后的理性是什么.一般来说,在 R 中表达这种相对复杂的查询最合适的方式是什么?我应该存储结果然后进一步缩小范围吗?

Could anyone help me please with this query? I am sure this is a normal behavior of getNodeSet, but I don't know what is the rational behind it. In general, what is the most appropriate way to phrase such relatively complicated queries in R? Should I store the result and then further narrow down?

非常感谢!

推荐答案

对于后续元素也使用相同的前缀:

use the same prefix for subsequent element as well :

//uniprot:feature[...]/uniprot:location

prefix + local-name 标识每个元素.如果您有带有默认名称空间的 XML(似乎这就是您所拥有的),则默认名称空间中会考虑所有没有前缀的元素.这就是为什么您需要为 XPath 中的每个元素(不仅仅是第一个元素)使用 前缀* 的原因.

prefix + local-name identify each element. In case you have XML with default namespace (seems this is what you have), all element without prefix considered in default namespace. That's the reason why you need to use the prefix* for each element in XPath (not only the first element).

*) 指向默认命名空间 URI 的前缀

这篇关于在 R 中使用 getNodeSet 进行复杂的 xPath 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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