English 中文(简体)
3. 与对应的成分
原标题:Find element with matching attribute
  • 时间:2011-08-18 16:31:23
  •  标签:
  • jquery
  • xml

我有几::

<myco:results xmlns:myco="http://myco.mycollp.com" resultsTypeID="StockChart">
    <myco:row xmlns:myco="http://myco.mycollp.com">
        <myco:price title="stock">0.6107013847</myco:price>
        <myco:price title="index">0.61965464</myco:price>
    </myco:row>
</myco:results>

我正在使用以下格乌拉:

$(xml).find("row").each(function () {

    var stockPrice = $(this).find("price[title= stock ]").text();
}

However stockPrice is always coming back as an empty string.

如果我检查:

$(this).find("price[title!= stock ]")

有效期为2年而不是1年,

$(this).find("price[title= stock ]")

长度为0。

我做了什么错误?

<>>>>>

我已经给人以全身的xml,带名字空间,但我没有这样做,这原本是为了使这个例子更清楚,但这可能是问题的根源,因此,现在就有了全面的XML。

最佳回答

在大韩民国,我设法利用黑手党开展工作。 @pimvdb建议的净网站。

var xml =  <myco:results xmlns:myco="http://myco.mycollp.com">
    <myco:row xmlns:myco="http://myco.mycollp.com">
        <myco:price title="stock">0.61</myco:price>
        <myco:price title="index">12.5</myco:price>
            </myco:row>
</<myco:results> ;

$(xml).find("myco\:row").each(function () {
    var stockPrice = $(this).find("myco\:price[title= stock ]").text();
    alert(stockPrice);
});

增 编

问题回答

here it is your selectors were incorrect while using a namespace: http://jsfiddle.net/PvakT/3/





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签