使用 javascript 解析 xml_file 时缺少数据。我正在尝试使用 HTML 和 Javascript 从 web 浏览器中的 xml 文件显示第一个孩子。问题是,第一个孩子的名字没有出现。注意:我使用的是谷歌浏览器。 Javascript:
<title>Read First Child</title>
<xml ID="Schriftsteller" SRC="D:\files\files\Schriftsteller.xml"></xml>
<script language="JavaScript">
function loadXMLDoc("D:\files\files\javascriptparser.html")
{
var xmlDoc;
if (window.XMLHttpRequest)
{
xmlDoc=new window.XMLHttpRequest();
xmlDoc.open("GET","D:\files\files\javascriptparser.html",false);
xmlDoc.send("");
return xmlDoc.responseXML;
}
// IE 5 and IE 6
else if (ActiveXObject("Microsoft.XMLDOM"))
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(XMLname);
return xmlDoc;
}
alert("Error loading document!");
return null;
}
function findWriter()
{
var Schriftsteller, schriftstellerKnoten, SpracheKnoten;
var FüllerKnoten, DichtungKnoten, Anzeige;
myXML = document.all("D:\files\files\Schriftsteller.xml").XMLDocument;
SchriftstellerKnoten = myXML.documentElement;
SpracheKnoten = SchriftstellerKnoten.firstChild;
DichtungKnoten = SpracheKnoten.firstChild;
FüllerKnoten = DichtungKnoten.firstChild;
NameNode = FüllerKnoten.firstChild;
Anzeige = NameNode.firstChild.nodeValue;
Documentar.show.me.value = Anzeige;
}
</script>
<span ID="blueBack">Read firstChild</span>
<div>
<form name="show">
<input type=text name="me">
<input type="button" value="Display Writer"
onClick="findWriter()">
</form>
</div>
</body>