【问题标题】:parse xml node child in jquery在 jquery 中解析 xml 节点子节点
【发布时间】:2013-06-05 20:56:28
【问题描述】:

我有以下 XML:

<item p4:stage="Ways and Means resolution" xmlns:p4="urn:services.parliament.uk-bills.ext"><guid isPermaLink="true">http://services.parliament.uk/bills/2013-14/antisocialbehaviourcrimeandpolicingbill.html</guid><link>http://services.parliament.uk/bills/2013-14/antisocialbehaviourcrimeandpolicingbill.html</link><category>Commons</category><category>Government Bill</category><title>Anti-social Behaviour, Crime and Policing</title><description>To make provision about anti-social behaviour, crime and disorder, including provision about recovery of possession of dwelling houses; to make provision amending the Dangerous Dogs Act 1991, Schedules 7 and 8 to the Terrorism Act 2000 and the Extradition Act 2003; to make provision about firearms and about forced marriage; to make provision about the police, the IndependentPolice Complaints Commission and the Serious Fraud Office; to make provision about criminal justice and court fees; and for connected purposes.</description><a10:updated>2013-06-05T17:42:59+01:00</a10:updated></item>

我可以使用这个解析&lt;item&gt;&lt;/item&gt; 中的所有内容:

$(xml).find('item').each(function() {
    var stage = $(this).find('title').text();
    console.log(stage);
});

但我正在看里面的东西:

<item....>  for example, 

我需要把里面的东西拉出来:

 <p4:stage></p4:stage>

我该如何取出这个?

提前谢谢你

【问题讨论】:

    标签: jquery xml-parsing


    【解决方案1】:

    在无效的 XML 中没有 &lt;p4:stage&gt;&lt;/p4:stage&gt;p4:stage 是 item 元素的属性

    $(xml).find('item').each(function() {
        var p4 = $(this).attr('p4:stage');
        console.log(p4);
    });
    

    FIDDLE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多