首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析jquery中的xml节点子节点

解析jquery中的xml节点子节点
EN

Stack Overflow用户
提问于 2013-06-06 04:56:28
回答 1查看 125关注 0票数 0

我有以下XML:

代码语言:javascript
复制
<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>

我可以使用下面的代码在<item></item>中解析所有这些内容:

代码语言:javascript
复制
$(xml).find('item').each(function() {
    var stage = $(this).find('title').text();
    console.log(stage);
});

但我看的是里面的东西:

代码语言:javascript
复制
<item....>  for example, 

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

代码语言:javascript
复制
 <p4:stage></p4:stage>

我该怎么把它拉出来呢?

提前谢谢你

EN

回答 1

Stack Overflow用户

发布于 2013-06-06 05:05:22

无效的XML中没有项目,p4:stage<p4:stage></p4:stage>元素的属性

代码语言:javascript
复制
$(xml).find('item').each(function() {
    var p4 = $(this).attr('p4:stage');
    console.log(p4);
});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16949723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档