Ciao
ecco un link dove puoi trovare tutto su come leggere un file xml usando
Msxml2.DOMDocument.3.0
http://www.w3schools.com/DOM/dom_examples.asp di seguito un esempio che puoi usare subito per vedere come visualizzare
il contenuto di un nodo, e/o di attributi dello stesso, contenuto
in un file xml.
Crea un file .html nel quale copiare il codice sotto.
<html>
<head>
<script type="text/javascript" src="loadxmldoc.js">
</script>
</head>
<body>
<script type="text/javascript">
text="<book>";
text=text+"<title>Everyday Italian</title>";
text=text+"<author id='2'>Giada De Laurentiis</author>";
text=text+"<year>2005</year>";
text=text+"</book>";
//funzioni per var testo
function loadXMLString(txt)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(txt);
return(xmlDoc);
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,"text/xml");
return(xmlDoc);
}
catch(e) {alert(e.message)}
}
return(null);
}
//funzione per file
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert("mess>> "+e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return (xmlDoc);
}
catch(e) {alert("mess>> "+e.message)}
return(null);
}
xmlDoc = loadXMLString(text);
x=xmlDoc.getElementsByTagName('author');
for (i=0;i<x.length;i++)
{
document.write("Autore>> "+x[i].childNodes[0].nodeValue);
document.write("<br />");
}
//output attributo 'id'
x=xmlDoc.getElementsByTagName("author")[0].attributes;
document.write("ID> "+x.getNamedItem("id").nodeValue);
document.write("<br />");
//Traverse a node tree
x=xmlDoc.documentElement.childNodes;
for (i=0;i<x.length;i++)
{
document.write(x[i].nodeName);
document.write(": ");
document.write(x[i].childNodes[0].nodeValue);
document.write("<br />");
}
</script>
</body>
</html>