简体   繁体   English

使用jQuery选择具有特定属性的xml中的节点

[英]Selecting Nodes in xml with an specific attribute with jQuery

after reading jquery xml select I wanted to do something similar with this rdf/xml: 阅读jquery xml选择之后,我想与此rdf / xml做类似的事情:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 <rdf:Description rdf:about="http://someURI/999">
  <dc:relation rdf:resource="http://www.someURI/888" />
 </rdf:Description>
 <rdf:Description rdf:about="http://www.someURI/001">
  <dc:relation rdf:resource="http://www.someURI/987/777"/>
 </rdf:Description>
</rdf:RDF>

I want to select the node with the attribute "rdf:about" ending with 001. I tried: 我想选择属性以“ rdf:about”结尾为001的节点。我尝试过:

var node = $(xml).find("rdf:Description[rdf:about$=001]");

But it wont work. 但它不会工作。 It returns the whole thing document. 它返回整个文档。 Any ideas? 有任何想法吗?

Edit: Corrected spelling error. 编辑:更正了拼写错误。 Doesn't change the problem, though. 但这并不会改变问题。

Uhm... I think is an escape problem. 嗯...我认为这是一个逃生问题。 Try to use 尝试使用

var node = $(xml).find("rdf\\:Description[rdf\\:about$=001]");

Run into similar problem. 遇到类似的问题。 For me dropping the namespace worked. 对我来说,删除名称空间是可行的。
So I would try something like: $(rdfDoc).find("Description[about$=001]"); 所以我会尝试类似的东西: $(rdfDoc).find("Description[about$=001]"); Not 100% sure about the attribute cause I was only trying to obtain node. 无法100%确定属性,因为我只是尝试获取节点。

Check your spelling. 检查您的拼写。 It's rdf:Description with an upper-case D . 它是带有大写Drdf:Description In XML, the case is significant. 在XML中,情况很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM