为什么在javascript中没有得到xml nodeValue? [英] why doesn't get xml nodeValue in javascript?

查看:32
本文介绍了为什么在javascript中没有得到xml nodeValue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (window.DOMParser) {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(txt,"text/xml");
}
else { // Internet Explorer 
    xmlDoc=new ActiveXObject("Microsoft.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 和 s1 返回 null,我不明白为什么?

s0 and s1 returned null and i dont understand why?

推荐答案

XML 元素的 nodeValue 属性始终为 null,因为元素内容实际上存储在文本中元素内的节点.如果内容足够简单,您可以执行以下操作:

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;

这篇关于为什么在javascript中没有得到xml nodeValue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆