Witam
Mam takie pytanie otóż mam zadanie zrobić plik xml, który będzie się składał z takich węzłów:
http://www84.zippyshare.com/v/6o0Vvo0k/file.html
I czy wg kodu to będzie np. coś takiego?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Animals [
<!ELEMENT Animals (Sharks+, Whales, Dolphins)>
<!ELEMENT Whales (#PCDATA)>
<!ELEMENT Dolphins (#PCDATA)>
<!ELEMENT Sharks (White+, Blue)>
<!ELEMENT Blue (#PCDATA)>
<!ELEMENT White (Age, Food, Color)>
<!ELEMENT Age (#PCDATA)>
<!ELEMENT Food (#PCDATA)>
<!ELEMENT Color (#PCDATA)>
<!ATTLIST Sharks id CDATA "id01">
]>
<Animals>
<Sharks id="id01">
<White>
<Age>55</Age>
<Food>Fishes</Food>
<Color>White</Color>
</White>
<Blue>Blue</Blue>
</Sharks>
<Whales>Whales</Whales>
<Dolphins>Dolphins</Dolphins>
</Animals>
I drugie pytanie gdyż chciałbym wczytać ten plik xml do html ale nie wiem dlaczego go nie wczytuje
Plik xml nazywa się animals.xml i jest w jednym katalogu z plikiem html
A to kod pliku html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Dokument bez tytułu</title>
</head>
<body>
<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
exampleFunction(this);
}
};
xmlhttp.open("GET", "animals.xml", true);
xmlhttp.send();
}
function exampleFunction(xml) {
var i, j;
var xmlDoc = xml.responseXML;
var data="";
var x = xmlDoc.getElementsByTagName("Sharks");
var y;
for (i = 0; i <x.length; i++) {
data += "<h2>Color1 ";
data += x[i].getElementsByTagName("White")[0].childNodes[0].nodeValue ;
data +="</h2><h3>Color2 ";
data += x[i].getElementsByTagName("Blue")[0].childNodes[0].nodeValue ;
data += "</h3>";
y = x[i].getElementsByTagName("Whales")[0].getElementsByTagName("Whales");
data += "<p><strong>Animal</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;
}
loadXMLDoc();
</script>
</body>
</html>
Firefox w konsoli nic nie pokazuje a chrome pokazał komunikat, że xml nie chce się załadować
index2.html:31 XMLHttpRequest cannot load file:///C:/Katalog/animals.xml. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.[/quote]
Proszę o pomoc
Pozdrawiam