[英]Parse xml data in javascript
console.log(id);
prints a function and thus a TypeError is thrown. function xmlParser(xmlResponse) {
if (window.DOMParser) {
parser = new DOMParser();
console.log(xmlResponse);
xmlDoc = parser.parseFromString(xmlResponse, "text/xml");
console.log(xmlDoc);
}
id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
console.log(id);
key = xmlDoc.getElementsByTagName("passkey")[0].childNodes[0].nodeValue;
console.log(key);
return format(id, key);
}
No, you don't need to convert response, because you can get xmlDoc
directly by responseXML
property. 不,您不需要转换响应,因为您可以直接通过
responseXML
属性获取xmlDoc
。
Example: 例:
xmlDoc = xmlResponse.responseXML; // you'll probably need to change it because I don't know what is value of xmlResponse in your case
id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
//and so on...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.