MICROSOFT.XMLDOM Traversal XML all node implementation code
All Microsoft XML Parser functions are formally recommended by the XML DOM of the consortium, except for the load and Loadxml functions (the formal DOM does not include standard functions loading XML documents). 13 node types supported by Microsoft XML Parser
Document Object Model (DOM)
DOM is the programming foundation for HTML and XML documents, and it defines the way to work with documents. Programmers can use DOM to add documents, locate document structures, add modifications, and delete document elements. The important goal of the consortium is to provide a programming interface that uses DOM for multiple platforms. The consortium DOM is designed to fit multiple platforms and can be implemented using any programming language.
<%
Dim Xml,objnode,objatr,ncntchd,ncntatr
Set Xml=server.createobject ("Microsoft.XMLDOM")
Xml.async=false
Xml.load (Server.MapPath ("Data.xml"))
Set Objnode=xml.documentelement
Ncntchd=objnode.childnodes.length-1
For I=0 to Ncntchd
Set Objatr=objnode.childnodes.item (i)
Ncntatr=objatr.attributes.length-1
For J=0 to Ncntatr
Response.Write Objatr.attributes.item (j) .text& "<br>"
Next
Response.Write "<br>"
Next
Response.Write "<br>"
Set objatr=nothing
Set objnode=nothing
Set xml=nothing
%>
Data.xml Document
<?xml version= "1.0" encoding= "Utf-8"?>
<root>
<row id= "1" compname= "Dalian" post= "063000" tel= "0315-2695" level= "888888888"/>
<row id= "2" compname= "Tianjun" post= "063000" tel= "0315-2695" level= "888888888"/>
<row id= "3" compname= "Beijin" post= "063000" tel= "0315-2695" level= "888888888"/>
</root>
Look at a code that uses the XML DOM to capture data
Open the XML file with the Xmldom method, if the local is not a problem, is the use of Server.MapPath ("Xml.xml") method, then the normal analysis of the content, but the direct use of the URL does not show the XML content (in the XMLDOM representation is the support URL way) , and then studied the discovery that the XMLHTTP method can be used to obtain XML and then analyze the code as follows:
Set Http=server.createobject ("Microsoft.XMLHTTP")
Http.open "Get", "Http://localhost/xml.xml", False
Http.send
Set Xml=server.createobject ("Microsoft.XMLDOM")
Xml.async=false
Xml.validateonparse=false
Xml.load (Http.responsexml)
If Xml.readystate>2 Then
Response.Write (the document is ready to go.) Status: "& Xml.readystate &" <br> ")
Set Item=xml.getelementsbytagname ("item")
For I=0 to (ITEM.LENGTH-1)
Set Title=item.item (i). getElementsByTagName ("title")
Set Link=item.item (i). getElementsByTagName ("link")
Response.Write ("<a href=" "" & Link.item (0). Text & "" > & Title.item (0). Text & "</a><br > ")
Next
Else
Response.Write ("The document is not ready yet.) Status: "& Xml.readystate &" <br> ")
End If
Set http=nothing
Set xml=nothing
The contents of the Xml.xml document are as follows:
<?xml version= "1.0" encoding= "Utf-8"
<channel>
<item>
<title> Test Document 1</ Title>
<link>http://localhost/</link>
</item>
<item>
<title> Test Document 2 </title>
<link>http://localhostindex.asp Tutorial </link>
</item>
</channel>