使用jquery检索xml名称空间子元素值

时间:2015-06-29 18:14:47

标签: javascript jquery xml namespaces

民间。

我是jquery的新手,在使用jquery解析命名空间格式.xml时,我检查了很多帖子。在查看我的代码并查看示例之后,我正在努力从嵌套的子元素中获取值。以下是我的xml片段:

<offers:offer-bundle>
<cash:offer lang="EN" offer-type="Cash">
<cash:cash>
<cash:cannot-be-combined-with></cash:cannot-be-combined-with>
<cash:cash-amount>1000</cash:cash-amount>
<cash:requires-tfs-financing>false</cash:requires-tfs-financing>
<cash:stackable-with-apr>false</cash:stackable-with-apr>
<cash:stackable-with-lease>false</cash:stackable-with-lease>
<cash:sub-type-labels>Cash Back</cash:sub-type-labels>
</cash:cash>
<cash:tfs-calculator>false</cash:tfs-calculator>
<cash:offer-label>Cash Back</cash:offer-label>
<cash:offer-label-num>7</cash:offer-label-num>
<cash:series-list></cash:series-list>
<cash:offer-id>cash_1433205220095</cash:offer-id>
<cash:start-date>2015-06-02</cash:start-date>
<cash:end-date>2015-07-06</cash:end-date>
<cash:title>2015 Cash Back Offer</cash:title>
<cash:use-for-email>false</cash:use-for-email>
<cash:description>I can get this value</cash:description>
<cash:offer-image/>
<cash:offer-image-alt/>
<cash:offer-image-disclaimer/>
<cash:offer-card>...</cash:offer-card>
<cash:bullets>...</cash:bullets>
<cash:disclaimers>
    <cash:disclaimer>
    **I NEED TO GET THIS CHILD ELEMENT VALUE.**
</cash:disclaimer>
</cash:disclaimers>
</offers:offer-bundle>

我可以获得<cash:offer-card><cash:offer-id&gt;的值因为它没有任何嵌套的孩子。我正在努力获得<cash:disclaimers>的子节点。

这是我到目前为止所写的内容:

$。AJAX({         输入:&#34; GET&#34;,         url:webServiceURL,         dataType:&#34; xml&#34;,         成功:function(xml){

    $(xml).find('offers\\:offer-bundle, offer-bundle').each(function(index, value) {


    var $incentive;
    var $offer;
    var $offerDescription;
    var $offerDisclaimer;

    //Do Cash: Condition code is executing, incentive is hard coded to 'cash'
    if (incentive == 'cash') {
        $incentive = $(this);
        $offer = $incentive.find('cash\\:offer, offer');
        $offerDescription = $offer.find('cash\\:description, description').text();
        $offer.find('cash\\:disclaimers, disclaimers').each(function (i, v) {

    console.log ("here executing" +  $(i).find('cash\\:disclaimer,       disclaimer').text()   );

我的控制台窗口打印出一个蓝色的小圆圈,其中包含数字2和#34;此处执行&#34;没有价值。即使我使用

$(this).find(&#39; cash \:免责声明,免责声明&#39;)。每个(函数(i,v){})与$ offer.find(&#39; cash \:免责声明) ,免责声明&#39;)。每个(函数(i,v){

我在控制台窗口中得到了相同的结果。任何想法或知识分享都会非常感激。

0 个答案:

没有答案