The common method of the DOM operation XML (all methods and properties of the DOM can be viewed to the VS object browser)
'Creating a DOM object set objdom = server.createObject ("Microsoft.xmldom")
'Take XML Data' Method 1 Take the XML Data of XML File ObjDom.Load ("C: / Test.xml") 'Method 2 Take the data of XML data strings ObjDom.LoadXML ("
'Create a node object set new = objDom.createElement ("people")' to this node to the value newnode.text = "people" 'Add attribute to this node set newattribute = objDom.createnode ("Attribute," Name ", "") NewAttribute.Text = "John Doe" Newnode.SetAttributeNode NewAttribute 'node is added to the child node Set NewnodeChild = objDom.CreateElement ( "address") Newnode.appendChild NewnodeChild' save this node object objDom.appendChild newnode objDom.save ( "c: /test.xml")
'Find a node object set objtofind = ObjDom.documentElement.selectsinglenode ("// people / man")' Remove the node name, node value, a property value of this node object, and all XMLNodeName = Objtofind.NodeNameNodeValue = Objtofind. TextObjtofind.getttributeNode ("name"). NodeValue 'attribute name is Name attribute value
'Take one attribute node object set objattrtofind = objdom.documentElement.SelectSingleNode ( "// people / man"). GetAttributeNode ( "name")' remove this node attribute name, attribute value nodeattrname = objattrtofind.nodenamenodeattrvalue = objattrtofind.nodevalue
'Remove a node object set objNode = objDom.documentElement.selectsinglenode ("// people / man")' To delete the node set objParentNode = ObjDom.DocumentElement.selectsinglenode ("// person") 'Parent node to delete the node to delete ObjparentNode.removeChild ObjNode
'Remove a node word point collection set objNodes = objDom.documentElement.selectsinglenode ("// people / man"). ChildNodes traversed this collection method 1 for Each Elementin ObjNodes Response.write Element.NodeName By Name Response.write Element.text byte point value next method 2Domlength = ObjNodes.Lengthfor i = 0 to Domlength-1 response.write objNodes.childNodes (i) .NodeName byte point name response.write objNodes.childNodes (i) .Text byte point value next 'property of a set of nodes extracted set objnodes = objdom.documentElement.SelectSingleNode ( "// people / man"). getAttributeNode ( "name"). attributes traverse the set for each element in objnodes response.write element.nodename attribute name Response.write element.nodevalue attribute value next ========================================= ============= <% DIM Xmldoc, NodeSet Xmldoc = Server.createObject ("msxml2.domdocument") xmldoc.async = false 'asynchronous transmission xmldoc.loadxml "
XMLDoc.createProcessinginstruction "XML", "Version = '1.0' Encoding = 'GB2312'"
Set node = xmlcreatenode (xmldoc, xmldoc.documentelement, "user", 0, 0, ")
Xmlcreatenode Xmldoc, Node, "Name", 1, 1, "SSM1226" Xmlcreatenode XMLDoc, Node, "Name", 0, 1, "said: rain people"
'********************************************************** ******** 'Function: Add a child node or attribute' xmldoc - XML DOM Object'Xmldocobj - To add a destination node object 'EleNameorattname - Node name or property name' key - 0-node; 1- 属 i f 无 无; 1- has' text - When IFTXT = 1 is effective, content 'BY' copyright information: Author: ssm1226; data: 2003-1-2; Copyright: Yeboss .NET '********************************************************* ********** function xmlCreateNode (xmldoc, xmldocObj, EleNameOrAttName, Key, ifTxt, Text) If Key = 0 then Dim SubNode set SubNode = xmldoc.createElement (EleNameOrAttName) if ifTxt = 1 then SubNode.text = Text xmldocObj.appendChild SubNode set xmlCreateNode = subNode set SubNode = Nothing ElseIf Key = 1 then Dim AttNode set AttNode = xmldoc.createAttribute (EleNameOrAttName) if ifTxt = 1 then AttNode.text = Text xmldocObj.attributes.setNamedItem AttNode set xmlCreateNode = AttNode set AttNode = Nothing end if End functionResponse.write xmldoc.xml%>