Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript在google chrome中加载xml文件_Javascript_Xml - Fatal编程技术网

如何使用javascript在google chrome中加载xml文件

如何使用javascript在google chrome中加载xml文件,javascript,xml,Javascript,Xml,我是网络编程的初学者,也是这个网站的新手。我试图获取xml标记的内容,但是当我在chrome中打开下面的代码时,什么都没有出现。有人能给我一个提示吗? 以下是完整的代码: <!DOCTYPE html> <html> <head> <script> var xmlDoc, xmlHttp; function readxml() { xmlHttp = new window.XMLHttpRequest(); xmlHttp.ope

我是网络编程的初学者,也是这个网站的新手。我试图获取xml标记的内容,但是当我在chrome中打开下面的代码时,什么都没有出现。有人能给我一个提示吗? 以下是完整的代码:

<!DOCTYPE html>
<html>
<head>
<script> 
var xmlDoc, xmlHttp;
function readxml()
{
    xmlHttp = new window.XMLHttpRequest();
    xmlHttp.open("GET","books.xml",false);
    xmlHttp.send(null);
    xmlDoc = xmlHttp.responseXML.documentElement;
    return xmlDoc;
}
</script>
</head>
<body>
<script>
var xmld
xmld=readxml();

document.write(xmld.getElementsByTagName("title")[0].childNodes[0].nodeValue + "<br>");
document.write(xmld.getElementsByTagName("author")[0].childNodes[0].nodeValue + "<br>");
document.write(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);
</script>
</body>
</html>

var-xmlDoc,xmlHttp;
函数readxml()
{
xmlHttp=newwindow.XMLHttpRequest();
open(“GET”,“books.xml”,false);
xmlHttp.send(空);
xmlDoc=xmlHttp.responseXML.documentElement;
返回xmlDoc;
}
变量xmld
xmld=readxml();
document.write(xmld.getElementsByTagName(“title”)[0]。childNodes[0]。nodeValue+“
”; document.write(xmld.getElementsByTagName(“作者”)[0]。childNodes[0]。nodeValue+“
”; document.write(xmlDoc.getElementsByTagName(“年”)[0].childNodes[0].nodeValue);
提示:函数
readxml
在加载xml之前返回。因此,您试图在拥有XML内容之前将其写入文档

查看本例中的
reqListener