Methods and examples for reading XML files using ASP

Source: Internet
Author: User

Save the following two sections of code, one of which is readxml. asp is saved as test. xml, put it under the same directory, debug the program, and I have explained it in the program. Reading the code can be used as a readxml function, you can use the input parameters to read different values of different xml data records. This program is adapted from the Internet. Please forgive me for any discrepancies. Copy codeThe Code is as follows: <%
Dim xml, objNode, objasd, nCntChd, nCntAtr
Set xml = Server. CreateObject ("Microsoft. XMLDOM ")
Xml. Async = False
Xml. Load (Server. MapPath ("test. xml "))

Set objnode1_xml.doc umentElement
NCntChd = objNode. ChildNodes. length-1

'This can define the value that asp reads from the xml file, and pass this value to determine the data to be read.

For I = 0 to nCntChd
Set objasd = objNode. ChildNodes. item (I)
NCntAtr = objret. Attributes. length-1

'All record items in a record are recorded starting from 0.
'Http://www.knowsky.com/

For j = 0 to nCntAtr
Response. write objret. Attributes. item (j). Text & "<br>"
Next
Response. write "<br>"
Next

Set objrecognition = Nothing
Set objNode = Nothing
Set xml = Nothing
%>

Xml fileCopy codeThe Code is as follows:The following is the program code:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Root>
<Row ID = "1" COMPNAME = "" ADDR = "Yuexiu District, Guangzhou City, Guangdong Province, Beijing Road" zip code = "510000" TEL = "8620-8333" PRODSERV = "business" Economic industry = "Sichuan noodle store" province = "Guangdong Province" city = "Guangzhou City" region = "Yuexiu District" visit = "0" priority = "9999999999" zhuangtai = "latest"/>
<Row ID = "2" COMPNAME = "" ADDR = "Guangzhou City, Guangdong Province" zip code = "510000" TEL = "8620-8330" PRODSERV = "Fast Food" Economic Industry = "Fast Food" province = "Guangdong Province" city = "Guangzhou City" region = "Yuexiu District" visit = "0" priority = "9999999999" zhuangtai = "latest"/>
<Row ID = "3" COMPNAME = "coriander Pavilion" ADDR = "Yuexiu District, Guangzhou City, Guangdong Province" zip code = "510000" TEL = "8620-837" PRODSERV = "Hunan cuisine" Economic Industry = "Hunan food" province = "Guangdong Province" city = "Guangzhou City" region = "Yuexiu District" visit = "0" priority = "9999999999" zhuangtai = "latest"/>
</Root>

A brief description of DOM objects and methods:
The documentElement attribute confirms the Root node of the XML file.
SelectSingleNode returns the first conforming node.
The loadXML method loads a piece of XML file or string.
The haschildnodes method returns true if the specified node has one or more subnodes.
The createElement method creates an element with a specified name.
Add a node to the AppendChild method as the final sub-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.