The ASP operates the main method and implementation of XML files through XMLDOM.

zhaozj2021-02-16  47

For small data, the XML file has many advantages in Access in retrieval updates.

I have tested that there is no database, put the membership information, product data information, transaction information, and website custom information, and the running results are very normal. It feels more than the database, but there is no test. Not sure. (Http://stone.yesku.net)

Let's talk about the main ways to create, query, modify the XML operation.

'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 'removed point a set of nodes byte set objnodes = objdom.documentElement.SelectSingleNode ( "// people / man"). ChildNodes traverse the collection method of 1 for each element in objnodes response.write element.nodename bytes named response.write element.text next byte point value method 2domlength = objnodes.lengthfor i = 0 to domlength-1 response.write objnodes.childnodes (i) .nodename byte named response.write objnodes.childnodes (i) .text Byte point value next

'Node a set of attributes extracted set objnodes = objdom.documentElement.SelectSingleNode ( "// people / man"). GetAttributeNode ( "name"). Attributes set for each element.nodename traverse the property name response element in objnodes response.write .write element.nodevalue attribute value Next

You can enjoy the XMLHTTP objects to implement the XMLHTTP objects to implement many features under ASP using XMLDOM objects.

转载请注明原文地址:https://www.9cbs.com/read-27022.html

New Post(0)