Reputation: 1589
I have a xml file and some tags have dots in it like this <m:properties></m:properties>
but when I try to read it it doesn't work.
This is the code how I read it:
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 file:
<?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>
and if I remove the : it works completely fine, is there anyway so I can keep the : and still read it ?
Upvotes: 1
Views: 277
Reputation: 111696
The XML is not well-formed. One way to make it well-formed, you've found, is to remove the namespace prefix (m:
) from m:properties
.
Alternatively, to keep the m:
, declare the namespace prefix:
<feed xmlns:m="http://www.example.com/m">
Without either eliminating the namespace prefix or declaring it, the XML is not well-formed and will not be parsed successfully by compliant XML parsers.
Upvotes: 1