admin管理员组文章数量:1432573
Here is a sample XML:
<xml id="javascriptObject">
<name>Joe</name>
<age>12</age>
<gender>M</gender>
</xml>
Object produced after digesting the XML above should be equivalent to:
var obj = {name: 'Joe', age: '12', gender: 'M'};
You guys know any functions in javascript or in jQuery that will convert the XML to a javascript object? If none, any ideas on how to do this the best way as possible? Thanks guys!
Here is a sample XML:
<xml id="javascriptObject">
<name>Joe</name>
<age>12</age>
<gender>M</gender>
</xml>
Object produced after digesting the XML above should be equivalent to:
var obj = {name: 'Joe', age: '12', gender: 'M'};
You guys know any functions in javascript or in jQuery that will convert the XML to a javascript object? If none, any ideas on how to do this the best way as possible? Thanks guys!
Share Improve this question asked May 7, 2013 at 4:28 RamRam 1,0844 gold badges16 silver badges26 bronze badges 2- Possible duplicate: stackoverflow./questions/1773550/… – Dan Commented May 7, 2013 at 4:31
- possible duplicate of how to convert xml to json using jquery – shyam Commented May 7, 2013 at 4:33
2 Answers
Reset to default 2Try this, using the parseXML() method:
var xml = '<xml id="javascriptObject"><name>Joe</name><age>12</age><gender>M</gender></xml>',
xmlDoc = $.parseXML(xml),
$xml = $(xmlDoc);
var obj = {
name: $xml.find('name').text(),
age: $xml.find('age').text(),
gender: $xml.find('gender').text()
};
console.log(obj);
you can use this project ;) this allows you to convert between json objects and XML objects
本文标签: Convert XML to Object using jQuery of plain javascriptStack Overflow
版权声明:本文标题:Convert XML to Object using jQuery of plain javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745589866a2665133.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论