A.xml:
Copy Code code as follows:
<?xml version= "1.0" encoding= "gb2312"?>
<pnode>
<node xmlid= "0"/>
<node xmlid= "1"/>
<node xmlid= "2"/>
<node xmlid= "3"/>
<node xmlid= "4"/>
</pnode>
javascript:
Copy Code code as follows:
<script language= "javascript" type= "Text/javascript" >
Load XML document
function Loadxml (xmlFile)
{
var xmldoc;
if (window. ActiveXObject)
{
xmldoc = new ActiveXObject (' Microsoft.XMLDOM ');
Xmldoc.async = false;
Xmldoc.load (XmlFile);
}
else if (document.implementation&&document.implementation.createdocument)
{
xmldoc = Document.implementation.createDocument (",", null);
Xmldoc.load (XmlFile);
}
Else
return null;
return xmldoc;
}
First, the XML object is judged
function Checkxmldocobj (xmlFile)
{
var xmldoc = Loadxml (xmlFile);
if (xmldoc==null)
{
Alert (' Your browser does not support XML file reads, so this page prohibits your operation, the recommended use of IE5.0 above can solve this problem! ');
return false;
}
return xmldoc;
}
var xmldoc=checkxmldocobj ("A.xml");
if (window. ActiveXObject) Xmldoc.removechild (Xmldoc.childnodes[0]);
var topm=xmldoc.getelementsbytagname ("Node1") [0].childnodes;
alert (topm.length);
</script>