//查找接点
var a = doc.getElementsByTagName("ttyp");
//var a = doc.selectNodes("//ttyp");
//显示改接点的属性
for(var i= 0;i<a.length;i++)
{
alert(a[i].xml);
for(var j=0;j<a[i].attributes.length;j++)
{
alert(a[i].attributes[j].name);
}
}
//修改节点,利用XPATH定位节点
var b = doc.selectSingleNode("//ttyp/sex");
b.text = "女";
//alert(doc.xml);
//XML保存(需要在服务端,客户端用FSO)
//doc.save();
//查看根接点XML
if(n)
{
alert(n.ownerDocument.xml);
}
//-->
</script>
-------------
<script language="javascript">
function window.onload()
{
var domXML=new ActiveXObject("Microsoft.xmldom");
domXML.load("Sele.xml");
var myRoot=domXML.documentElement;
var myNodes2=myRoot.childNodes;
var myNode2=myNodes2.nextNode();
var tableStr="";
for(var i=0;i<myNodes2.length;i++)
{
myNodes3=myNode2.childNodes;
myNode3=myNodes3.nextNode();
tableStr=tableStr+"<tr>";
for(var j=0;j<myNodes3.length;j++)
{
tableStr=tableStr+"<td width=100 bgcolor='#F3432A'>" + myNode3.text + "</td>";
myNode3=myNodes3.nextNode();
}
myNode=myNodes2.nextNode();
tableStr=tableStr + "</tr>";
}
tableStr="<table width=800 border=1><tr><td>CPU</td><td>内存</td><td>主板</td><td>硬盘</td></tr>" + tableStr + "</table>";
document.all.lideyongValue.innerHTML=tableStr;
}
</script>
-------------
首先,我们需要加载这个xml文件,js中加载xml文件,是通过XMLDOM来进行的.
// 加载xml文档
loadXML = function(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;