Witam
Mam problem z podłaczeniem pliku xml do html. Nie mam pojęcia gdzie jest błąd. W konsoli pokazuje ze jest okey. Próbowałem przez serwer też nie działa. Proszę o pomoc :)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalogue [
<!ELEMENT catalogue (note+)>
<!ELEMENT note (#PCDATA|types|company|model|accessories)*>
<!ELEMENT type (#PCDATA)>
<!ELEMENT size (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT accessories (#PCDATA)>
<!ELEMENT types (type,size)>
<!ATTLIST types number CDATA "0">
<!ATTLIST note id CDATA "0">
]>
<catalogue>
<note id="1" >
<types number="561" >
<type>kolarzowka</type>
<size>L</size>
</types>
<company>trek</company>
<model>oclv</model>
<accessories>ultegra</accessories>
</note>
<note id="2">
<types number="562">
<type>kolarzowka</type>
<size>L</size>
</types>
<company>trek</company>
<model>oclv</model>
<accessories>ultegra</accessories>
</note>
</catalogue>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<section id="xmlContent">
<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest(); //definiujemy obiekt
xmlhttp.onreadystatechange = function() { //sprawdzamy status
if (this.readyState == 4 && this.status == 200) {
//jeśli wszystko jest ok, odpalamy naszą metodę do danych
exampleFunction(this);
}
};
xmlhttp.open("GET", "data.xml", true); //otwieramy połączenie
xmlhttp.send(); //wysyłamy żadanie
}
function exampleFunction(xml) {
var i;
var xmlDoc = xml.responseXML; //odpowiedź z danymi
var data="";
var x = xmlDoc.getElementsByTagName("note"); //elementy <note>
var y;
for (i = 0; i <x.length; i++) {
data += "<h2>Artist Name: ";
data += "<h2>note: " + x[i].childNodes[0].nodeValue + ": "+ x[i].getAttribute('ID') +"</h2>";
z = x[i].getElementsByTagName("company");
data += x[i].getElementsByTagName("company")[0].childNodes[0].nodeValue ;
data +="</h2><h3>model: "
data += x[i].getElementsByTagName("model")[0].childNodes[0].nodeValue ;
data += "</h3>";
y = x[i].getElementsByTagName("types")[0].getElementsByTagName("type");
data += "<p><strong>Music category:</strong></p><ul>";
for(j = 0; j <y.length; j++) {
data += "<li>" + y[j].childNodes[0].nodeValue+ "</li>";
}
data += "</ul>";
}
document.getElementById("xmlContent").innerHTML = data;
}
</script>
</section >
</body>
</html>