js 操作xml

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async = false;

xmlDoc.loadXML(text);

xmlDoc.load("stu.xml");

 

转换string  

xmlDoc.xml

 

var Count = xmlDoc.selectNodes('/TableData')[0].childNodes.length

node .text = "星际";

 

node ..setAttribute("index", 'xxx');

pnode.removeChild(node);

nodes[0].getAttribute('index');

  1. //增加结点   
  2.     function add_node(){  
  3.         var  oxh = xmlDoc.createElement("学号" );  
  4.         oxh.appendChild(xmlDoc.createTextNode(xh.value));  
  5.         var  oxm = xmlDoc.createElement("姓名" );  
  6.         oxm.appendChild(xmlDoc.createTextNode(xm.value));  
  7.         var  oxb = xmlDoc.createElement("性别" );  
  8.         oxb.appendChild(xmlDoc.createTextNode(xb.value));  
  9.         var  ojg = xmlDoc.createElement("籍贯" );  
  10.         ojg.appendChild(xmlDoc.createTextNode(jg.value));  
  11.   
  12.         var oxs = xmlDoc.createElement("学生" );  
  13.         oxs.appendChild(oxh);  
  14.         oxs.appendChild(oxm);  
  15.         oxs.appendChild(oxb);  
  16.         oxs.appendChild(ojg);  
  17.   
  18.         var parent = xmlDoc.selectSingleNode("/学生管理" );  
  19.         if (parent.hasChildNodes())   {     
  20.            parent.insertBefore(oxs,parent.firstChild);     
  21.           }else {     
  22.            parent.appendChild(oxs);     
  23.           }   
  24.     } 

你可能感兴趣的:(xml,Microsoft)