日期:2014-05-18  浏览次数:20392 次

为什么我读不出XML节点中的数据?
XMLFile.xml:
<?xml version="1.0" encoding="utf-8" ?>
<people>
  <name>xumin</name>
  <sex>man</sex>
  <birthday>19791010</birthday>
</people>

js代码:
var xmldom =new ActiveXObject("MicroSoft.XMLDom");
xmldom.async=false;
xmldom.load("XMLFile.xml");
function Button1_onclick(){
  var rootNode;
  var Text1=document.getElementById("text1");
  rootNode=xmldom.documentElement;//取得文件根元素
  var n=rootNode.selectSingleNode("name");
  Text1.value=n.Text; //显示元素内容
}
这些代码显示数据时是null

如果我要将xml文件当数据库用,用selectSingleNode查找name='xumin'的一整条记录,包括sex,birthday字段,应该怎么写代码?

------解决方案--------------------
Javascript是大小写敏感的

n.text

或者
n.getTextNode().value




var p = xmldom.selectSingleNode("//people");
alert(p.childNodes[0].text);
alert(p.childNodes[1].text);
alert(p.childNodes[2].text);