H�ufig mu�t du dich durch Element in einem der XML Dokument oder Zeichenkette schlingen.
Das Beispiel unterhalb der Schleifen durch alle KindNodes von <note>,und drucken den Nodenamen und den Nodewert jedes Nodess:
<html>
<body>
<script type="text/javascript">
var text="<note>";
text=text+"<to>Tove</to>";
text=text+"<from>Jani</from>";
text=text+"<heading>Reminder</heading>";
text=text+"<body>Don't forget me this weekend!</body>";
text=text+"</note>";
// code for IE
if (window.ActiveXObject)
{
var doc=new ActiveXObject("Microsoft.XMLDOM");
doc.async="false";
doc.loadXML(text);
}
// code for Mozilla, Firefox, Opera, etc.
else
{
var parser=new DOMParser();
var doc=parser.parseFromString(text,"text/xml");
}
// documentElement always represents the root node
var x=doc.documentElement;
for (i=0;i<x.childNodes.length;i++)
{
document.write(x.childNodes[i].nodeName);
document.write("=");
document.write(x.childNodes[i].childNodes[0].nodeValue);
document.write("<br />");
}
</script>
</body>
</html>
O/P:
to=Tove
from=Jani
heading=Reminder
body=Don't forget me this weekend!
Keywords:
xml document, xml file, xml parser, xmldom microsoft.xmldom, text node, xml dom attribute, document object model