How ASP reads XML data files

Source: Internet
Author: User

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
'这个可以定义asp读取xml文件的那一个值,通过传递这个值来确定读取的数据
for i=0 to nCntChd
set objAtr=objNode.ChildNodes.item(i)
nCntAtr=objAtr.Attributes.length-1
'历遍一条记录里面的所有的记录项,记录是从0开始的
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="过桥轩" ADDR="广东省广州市越秀区北京路" 邮编="510000" TEL="8620-8333" PRODSERV="经营面" 经济行业="粥粉面店" 省份="广东省" 地市="广州市" 区域="越秀区" visit="0" 优先级="9999999999" zhuangtai="最新"/>
<row ID="2" COMPNAME="周仔" ADDR="广东省广州市" 邮编="510000" TEL="8620-8330" PRODSERV="经营快餐饮食" 经济行业="快餐" 省份="广东省" 地市="广州市" 区域="越秀区" visit="0" 优先级="9999999999" zhuangtai="最新"/>
<row ID="3" COMPNAME="香菜馆" ADDR="广东省广州市越秀区" 邮编="510000" TEL="8620-837" PRODSERV="经营湘菜" 经济行业="湘菜" 省份="广东省" 地市="广州市" 区域="越秀区" visit="0" 优先级="9999999999" zhuangtai="最新"/>
</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.