Asp reads xml

Source: Internet
Author: User

The tree. xml file is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?>
<CategoryTree>
<Category parentid = "0">
<Id> 1 </id>
<Title> ASP. NET </title>
<Url> </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "1">
<Id> 2 </id>
<Title> GridView </title>
<Url> http://www.asp.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "1">
<Id> 3 </id>
<Title> DataList </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "1">
<Id> 4 </id>
<Title> ListView </title>
<Url> http://www.codeproject.com </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "1">
<Id> 5 </id>
<Title> Reapter </title>
<Url> http://baidu.com </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "0">
<Id> 6 </id>
<Title> Create Code </title>
<Url> </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 7 </id>
<Title> Generate a line table </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 8 </id>
<Title> Generate a GridView </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 9 </id>
<Title> Generate a line table </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 10 </id>
<Title> Generate a GridView </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 13 </id>
<Title> Generate a line table </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 14 </id>
<Title> Generate a GridView </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 11 </id>
<Title> Generate a line table </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 12 </id>
<Title> Generate a GridView </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 15 </id>
<Title> Generate a line table </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
<Category parentid = "6">
<Id> 16 </id>
<Title> Generate a GridView </title>
<Url> http://www.codefans.net </url>
<Addtime> 2008-7-6 </addtime>
</Category>
</CategoryTree>

  

The xmlread. asp file is as follows:

  

<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>

<%
Dim xml, objNode, objasd, nCntChd, nCntAtr, nCntNd, xmlStr
Set xml = Server. CreateObject ("Microsoft. XMLDOM ")
Xml. Async = False
 
'An xml file is equivalent to a data table, and the xml root node is equivalent to the data table name.
Xml. Load (Server. MapPath ("tree. xml "))
 
'Get each level-1 node in the xml file. The level-1 node is equivalent to a record in the data table.
Set objnode1_xml.doc umentElement
'Obtain the number of first-level nodes, that is, the number of records in the data table.
NCntChd = objNode. ChildNodes. length-1
 
'Traverse each level-1 node, that is, traverse each record
For I = 0 to nCntChd
Set objasd = objNode. ChildNodes. item (I) 'get the I-level node under the root node, that is, get the I-level record in the data table.

NCntAtr = objret. Attributes. length-1 'Get the number of Attributes of the first-level node
'Review all attribute items in a record. The Attribute Index starts from 0.
For j = 0 to nCntAtr
XmlStr = xmlStr & objasd. Attributes. item (j). nodeName & ":" 'read node attribute name
XmlStr = xmlStr & objasd. Attributes. item (j). Text & "& nbsp;" 'read node attribute values
Next

XmlStr = xmlStr & "<br>"

NCntNd = objacc. ChildNodes. length-1 'Get the number of subnodes of the current primary node
For k = 0 to nCntNd
XmlStr = xmlStr & "<br> & nbsp;" & objtarget. ChildNodes. item (k). nodeName & ":" 'name of the read Node
XmlStr = xmlStr & objasd. ChildNodes. item (k). text' read the node Value
Next

XmlStr = xmlStr & "<br>"
Next

 
Response. Write (xmlStr)
 
Set objrecognition = Nothing
Set objNode = Nothing
Set xml = Nothing
%>

 

 

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.