First look at the XML file
Text.xml' encoding use gb2312 Chinese, if you want to use it in English utf-8
<?xml version= "1.0" encoding= "gb2312"?><root><row id= "2" compname= "Lightning" addr= "Hebei Tangshan" Zip code = "063000" tel= "0315-2695" prodserv= "Web page teaching" Economic industry = "Web page production" province = "Hebei province" to "City" Tangshan "zone =" Lunan District "visit=" 0 "priority =" 888888888 "zhuangtai=" latest "/><row id= "3" compname= "Web teaching qwwqq" addr= "Hebei Tangshan AAA" ZIP code = "063000" tel= "0315-2695" prodserv= "web teaching" Economic industry = "page making" province = " Hebei province "Ground city =" Tangshan "area =" Lunan District "visit=" 0 "priority =" 888888888 "zhuangtai=" latest "/><row id= "4" compname= "Sdfds" addr= "Sdfds" Zip code = "Sdfds" tel= "Sdfds" prodserv= "Sdfds" economic industry = "Sdfds" province = "Sdfds" city = " Sdfds "zone =" Sdfds "visit=" Sdfds "priority =" Sdfds "zhuangtai= " Sdfds "/><row id= "5" compname= "ASD" addr= "ASD" Postal code = "ASD" tel= "ASD" prodserv= "ASD" Economy industry = "ASD" province = "asd" to City = "asd" area = "ASD" Visi T= "ASD" priority = "ASD" zhuangtai= "ASD"/><row id= "6" compname= "M" addr= "m" Zip code = "M" tel= "M" prodserv= "m" economic industry = "M" province = "m" city = "m" area = "M" visit= "m" priority = "M" Zhuan gtai= "M"/></root>read the XML file, index.asp<%path= "Text.xml" Dim Xml,objnode,objatr,ncntchd,ncntatrset Xml=server.createobject ("Microsoft.XMLDOM") Xml.validateonparse = Truexml.load (Server.MapPath (path)) XML. Async=falseset Objnode=xml.documentelementncntchd=objnode.childnodes.length-1 ' This defines the value that an ASP can read from an XML file, By passing this value to determine the data read%><table width= "90%" border= "0" cellspacing= "0" cellpadding= "0" > <tr> <% for h=0 to ncntchd %> <td height= "align=" Center > name </td> <% next %> <td Height = "><a" href= "addxmlinfo.asp" > Add </a> </td> </tr><%for i=0 to Ncntchdset Objatr=objnode.childnodes.item (i) ncntatr=objatr.attributes.length-1 ' calendar all the entries in a record, starting from 0%><tr> <%for j=0 to ncntatr%> <td height= "+" align= "center" valign= "Middle" ><%= ObjAtr.Attributes.item (j). text%></td> <% ' RESPONSE.WRIte ObjAtr.Attributes.item (j). text& "<br>" next%><td height= "align=" center "valign=" middle "><a href=" modxml.asp?id=<% =i%> "> Modify </a> <a href=" delxml.asp?id=<%=i%> "> Delete </a></td></tr><%next% ></table><%set Objatr=nothingset Objnode=nothing set xml=nothing %>Add XML file Contentsaddxmlinfo.asp<% Dim Xml,objnode,objatr,ncntchd,ncntatr Set xml=server.createobject ("Microsoft.XMLDOM")xml.validateonparse = TrueXML. Load (Server.MapPath ("Text.xml"))XML. Async=falseSet objnode=xml.documentelementncntchd=objnode.childnodes.length-1set Objatr=objnode.childnodes.item (NCNTCHD)ncntatr=objatr.attributes.length-1%><form action= "addxml.asp" method= "POST" ><table width= "43%" border= "0" cellspacing= "0" cellpadding= "0" ><%For n=0 to Ncntatr%><tr><td><%=objatr.attributes.item (n). Name%></td><%if ObjAtr.Attributes.item (n). Name= "ID" Then%><td align= "left" ><input type= "text" Name= "<%=objatr.attributes.item (n). Name%> "value=" <%=cint (ObjAtr.Attributes.item (n). Text) +1%> "/></td><%Else%><td align= "left" ><input type= "text" Name= "<%=objatr.attributes.item (n). Name%> "value=" "/></td><%End If%></tr><%Next%><tr><td><input type= "Submit" value= "Add"/></td></tr></table></form><%Set objatr=nothingSet objnode=nothingSet xml=nothing%>Addxml.asp<%Dim Xml,objnode,objatr,ncntchd,ncntatrSet xml=server.createobject ("Microsoft.XMLDOM")xml.validateonparse = TrueXML. Load (Server.MapPath ("Text.xml"))XML. Async=falseSet objnode=xml.documentelementSet row = Xml.createnode (1, "Row", "")objnode.appendchild (Row)XML. Save (Server.MapPath ("Text.xml"))' last ID numberncntchd=objnode.childnodes.length-1 set Objatr=objnode.childnodes.item (nCntChd-1)ncntatr=objatr.attributes.length-1For n=0 to Ncntatr Call xml.getelementsbytagname ("Row"). Item (XML. documentelement.childnodes.length-1). SetAttribute ("" &objatr.attributes.item (N). name& "", "" &trim (Request. Form (ObjAtr.Attributes.item (n). Name)) & "")NextXML. Save (Server.MapPath ("Text.xml"))Set objatr=nothingSet row=nothingSet objnode=nothingSet xml=nothingResponse. Write "<script>alert (' Add success! '); location.href= ' readxml.asp ';</script> " %>Now that you've added it, you're going to modify and delete it.Modifying an XML fileModxml.asp<%Dim idid=request ("id")if id<> "" Then Dim Xml,objnode,objatr,ncntchd,ncntatr Set xml=server.createobject ("Microsoft.XMLDOM")xml.validateonparse = TrueXML. Load (Server.MapPath ("Text.xml"))XML. Async=falseSet objnode=xml.documentelement set Objatr=objnode.childnodes.item (ID)ncntatr=objatr.attributes.length-1%><form action= "modxmlinfo.asp" method= "POST" ><table width= "43%" border= "0" cellspacing= "0" cellpadding= "0" ><%For n=0 to Ncntatr%><tr><td><%=objatr.attributes.item (n). Name%></td><td align= "left" ><input type= "text" name= "atr<%=n%>" value= "<%=objatr.attributes.item (n). Text%> "/></td></tr><%Next%><tr><td><input type= "Submit" value= "Modify"/><input name= "id" type= "hidden" id= "id" value= "<%=id%>"/></td></tr></table></form><%End If%><%Set objatr=nothingSet objnode=nothingSet xml=nothing%>modxmlinfo.asp<%Dim idid=request ("id")if id<> "" ThenDim Xml,objnode,objatr,ncntchd,ncntatrSet xml=server.createobject ("Microsoft.XMLDOM")xml.validateonparse = TrueXML. Load (Server.MapPath ("Text.xml"))XML. Async=falseSet objnode=xml.documentelementset Objatr=objnode.childnodes.item (ID)ncntatr=objatr.attributes.length-1For c=0 to NcntatrObjAtr.Attributes.item (c). Text=request. Form ("Atr" &c)' response. Write request. Form ("Atr" &c)' response. Write "<>"NextXml.save (Server.MapPath ("Text.xml"))End IfSet objatr=nothingSet objnode=nothingSet xml=nothingResponse. Write "<script>alert (' Save succeeded '); location.href= ' readxml.asp ' </script>"%>The changes are complete, and then only the deleteddelxml.asp<% Dim idid=request ("id")if id<> "" ThenDim Xml,objnode,objatr,ncntchd,ncntatrSet xml=server.createobject ("Microsoft.XMLDOM")xml.validateonparse = TrueXML. Load (Server.MapPath ("Text.xml"))XML. Async=falseSet objnode=xml.documentelementObjnode.removechild (ObjNode.ChildNodes.item (ID))Xml.save (Server.MapPath ("Text.xml"))End IfSet objatr=nothingSet objnode=nothingSet xml=nothingResponse. Write "<script>alert (' Save succeeded '); location.href= ' readxml.asp ' </script>"%>
The increment, delete, change and check of XML by ASP