Code Explanation: ASP Read XML data file method

Source: Internet
Author: User
Tags zip
xml| Data | Save the following two pieces of code separately, One save for readxml.asp another save as Test.xml, placed under the same directory, debugger can, in the program I have explained, read the code can be made into a readxml function, by using the input parameters to read XML different data records of different values. This program is adapted from the internet, what is the discrepancy please forgive me.

readxml.asp
<%
Dim Xml,objnode,objatr,ncntchd,ncntatr
Set xml=server.createobject ("Microsoft.XMLDOM")
Xml. Async=false
Xml. Load (Server.MapPath ("Test.xml"))

Set objnode=xml.documentelement
Ncntchd=objnode.childnodes.length-1

' This defines the value that the ASP reads from the XML file, passing this value to determine which data to read

For I=0 to Ncntchd
Set Objatr=objnode.childnodes.item (i)
Ncntatr=objatr.attributes.length-1

' All the entries in a record, starting with the 0 record.

For J=0 to Ncntatr
Response.Write ObjAtr.Attributes.item (j). text& "<br>"
Next
Response.Write "<br>"
Next

Set objatr=nothing
Set objnode=nothing
Set xml=nothing
%>

Test.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<root>
<row id= "1" compname= "Bridge Porch" addr= "Guangdong province Guangzhou Yuexiu District Beijing Road" Zip code = "510000" tel= "8620-8333" prodserv= "business face" economic industry = "Congee Noodle shop" province = "Guangdong province" city = " Guangzhou "area =" Yuexiu District "visit=" 0 "priority =" 9999999999 "zhuangtai=" latest "/>
<row id= "2" compname= "Zhou Chai" addr= "Guangdong province Guangzhou" Zip code = "510000" tel= "8620-8330" prodserv= "Operating fast food" economic industry = "fast food" province = "Guangdong province" city = "Guangzhou" area = "Yuexiu District" visit= "0" priority = "9999999999" zhuangtai= "newest"/>
<row id= "3" compname= "coriander Hall" addr= "Guangzhou Yuexiu District, Guangdong Province" Zip code = "510000" tel= "8620-837" prodserv= "operating Hunan" economic industry = "Hunan" province = "Guangdong province" city = "Guangzhou" area = "Yuexiu District" visit= "0" priority = "9999999999" zhuangtai= "newest"/>
</root>

A brief description of the objects and methods of the DOM:
The DocumentElement property confirms the root (root) node of the XML file.
selectSingleNode returns the first node that conforms to the style.
The Loadxml method loads a fragment of an XML file or string.
HasChildNodes method if the specified node has one or more child nodes, the return value is true.
The CreateElement method creates an element with the specified name.
The AppendChild method plus a node is treated as the last child node of the specified node.
The Createcdatasection method creates a CDATA that contains specific data.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.