这段代码什么问题
- JScript code
function parseXML(){ //解析XML文件 var xmlDoc = window.ActiveXObject? new ActiveXObject("Microsoft.XMLDOM"):document.implementation.createDocument("","",null); if(xmlDoc != null){ xmlDoc.async = false; xmlDoc.load("test.xml");//加载XML文件 document.write(xmlDoc.getElementsByTagName("to").length); }else { document.write("error"); } }
- XML code
<?xml version="1.0" encoding="gb2312"?><!DOCTYPE note SYSTEM "note.dtd"><note id="small" value="2"> <to father="hai"> <firstname>yu</firstname> <familyname>hai</familyname> </to> <to father="haid"> <firstname>yud</firstname> <familyname>haidfd</familyname> </to> <from>yuhai</from> <heading>testing</heading> <body content="1">sdfsd &writer; &version;</body></note>
****************************************
结果打印 0 且无论换成什么元素打印结果都是 0
请问这是什么原因?
[解决办法]
好帖子
[解决办法]
明显你的xml不是良构的!&要xml中要用实体代替&或用<![CDATA[ ...]]>包裹一下