开发者

why doesn't get xml nodeValue in javascript?

开发者 https://www.devze.com 2023-02-11 07:57 出处:网络
if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,\"text/xml\"); } else { // Internet Explorer
if (window.DOMParser) {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(txt,"text/xml");
}
else { // Internet Explorer 
    xmlDoc=new ActiveXObject("Mi开发者_如何学JAVAcrosoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(txt); 
}
                /*copy ends*/
temp = xmlDoc.getElementsByTagName('COMMENT');
s0 = xmlDoc.getElementsByTagName('TITLE')[i].nodeValue;
s1 = xmlDoc.getElementsByTagName('CMT')[i].nodeValue;

s0 and s1 returned null and i dont understand why?


The nodeValue property of XML elements is always null, because the element content is actually stored within text nodes inside the element. If the content is simple enough, you can do something like:

s0 = xmlDoc.getElementsByTagName("TITLE")[i].firstChild.nodeValue;
s1 = xmlDoc.getElementsByTagName("CMT")[i].firstChild.nodeValue;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号