[英]parsing xml in jquery
I am trying to read a XML file in jquery and then use dom manipulation on it. 我试图在jquery中读取XML文件,然后使用dom操作。 But whenever I parse my xml using $.parseXML(xml) it gives me null object.
但是,每当我使用$ .parseXML(xml)解析xml时,都会给我空对象。 Please help me in this regard.
请帮助我这方面。
My jquery code is as follows: 我的jquery代码如下:
var main=function() {
console.log("hi there");
var $xml;
$.ajax({
type: "GET",
url: "xml/test.xml",
dataType: "xml",
success: function (xml) {
console.log(xml);
var xmlDoc = $.parseXML(xml);
console.log(xmlDoc);
$xml = $(xmlDoc);
console.log($xml);
}
});
};
$(document).ready(main);
my output is as follows: 我的输出如下:
My test.xml file is as follows : 我的test.xml文件如下:
<?xml version='1.0' ?>
<doc>
<person>
<name>sachin</name>
<age>21</age>
</person>
<person>
<name>Akash</name>
<age>18</age>
</person>
</doc>
Passing dataType: "xml"
tells jQuery to call parseXML
for you. 传递
dataType: "xml"
告诉jQuery为你调用parseXML
。
You don't need to do anything. 你不需要做任何事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.