【发布时间】:2015-10-06 19:54:20
【问题描述】:
我有一个 xml 文件,其中一些标签中有像这样的点 <m:properties></m:properties>
但是当我尝试阅读它时它不起作用。
这是我阅读的代码:
displayCD(0);
function displayCD(i) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp, i);
}
}
xmlhttp.open("GET", "text.xml", true);
xmlhttp.send();
}
function myFunction(xml, i) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("ENTRY");
document.getElementById("text").innerHTML =
"Artist: " +
x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue +
"<br>Title: " +
x[i].getElementsByTagName("type")[0].childNodes[0].nodeValue +
"<br>Year: " +
x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue +
"<br>Price: " +
x[i].getElementsByTagName("body")[0].childNodes[0].nodeValue +
"<br>Price: " +
x[i].getElementsByTagName("expires")[0].childNodes[0].nodeValue;
}
xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<feed>
<ENTRY>
<content>
<m:properties>
<id>41</id>
<type>Hallo meneer</type>
<title>MAILING</title>
<body>Just some random content Hi !</body>
<expires>2013-07-11</expires>
</m:properties>
</content>
</ENTRY>
</feed>
如果我删除 : 它完全可以正常工作,无论如何我可以保留 : 并仍然阅读它吗?
【问题讨论】:
-
所谓的xml命名空间
-
@T.G 我编辑了帖子。
-
@Nanoc 好的,我明白了,但是我如何调用 id。不能正常工作?
-
我不知道为什么你最近的问题遭到了反对,但我正要回答它,然后你才删除它......
-
因为人家哭的太快了哈哈,不过你能不能再聊聊还帮帮我呢? @詹姆斯唐纳利
标签: xml