<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore> <book category="COOKING"> <title lang="en">EverydayItalian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J.K.Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQueryKickStart</title> <author>James McGovern</author> <author>PerBothner</author> <author>Kurt Cagle</author> <author>JamesLinn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T.Ray</author> <year>2003</year> <price>39.95</price> </book>
</bookstore>
HTML5-Quellcode mit Abfrage
<!DOCTYPE html> <html> <head> <title>Abfrage</title> <head> <body> <script>function loadXMLDoc(dname){if(window.XMLHttpRequest){xhttp=newXMLHttpRequest();}else{xhttp=newActiveXObject("Microsoft.XMLHTTP");}xhttp.open("GET",dname,false);xhttp.send("");return xhttp.responseXML;}xml=loadXMLDoc("books.xml");path="/bookstore/book/title"// Code für IEif (window.ActiveXObject){var nodes=xml.selectNodes(path);for (i=0;i<nodes.length;i++){document.write(nodes[i].childNodes[0].nodeValue);document.write("<br>");}}// Code für Mozilla, Firefox, Opera, etc.elseif (document.implementation &&document.implementation.createDocument){var nodes=xml.evaluate(path, xml, null,XPathResult.ANY_TYPE, null);var result=nodes.iterateNext();while (result){document.write(result.childNodes[0].nodeValue);document.write("<br>");result=nodes.iterateNext();}}</script> </body> </html>