Witam. Od pewnego czasu zmagam się z xml i nie za bardzo mi to wychodzi :/ do tego stopnia że tutorial przepisany/przekopiowany z internetu nie chce chodzić :D Ma ktoś pomysł dlaczego to nie chce działać? Tyle czasu próbuję zgłębić ten problem, że zaczynam się już poddawać
Link do tutorialu
<html>
<head>
<title>Reading XML file</title>
<script>
function readXML()
{
var xml = new XMLHttpRequest();
xml.open('GET','xml.xml, false');
xml.send();
var xmlData = xml.responseXML;
if(!xmlData)
{
xmlData = (new DOMParser()).parseFromString(xml.responseText, 'text/xml');
var emp = xmlData.getElementsByTagName("employee");
var name = emp[0].getElementsByTagName("name")[0].firstChild.data;
var age = emp[0].getElementsByTagName("age")[0].firstChild.data;
var salary = emp[0].getElementsByTagName("salary")[0].firstChild.data;
document.write("Name="+name+"<br>");
document.write("Age="+age+"<br>");
document.write("salary="+salary+"<br>");
}
}
</script>
</head>
<body>
<h1>XML File</h1>
<button onclick="readXML()">Read XML File</button>
</body>
</html>
<?xml version="1.0"?>
<company>
<employee>
<name>Chrish</name>
<age>40</age>
<salary>$2000</salary>
</employee>
</company>