ASP traverses the content of each XML Node

Source: Internet
Author: User
Books. asp
<%
''Create an XML Object
Set objxmldom = server. Createobject ("Microsoft. xmldom ")
''Specifies whether the XML file download is asynchronous with the XML Processing
Objxmldom. async = false
''To get the Directory and file name of the XML file. Here is the virtual directory.
Filestr = server. mappath ("./") & "/books. xml"
''Load the XML file
Objxmldom. Load (filestr)

''To get the length of the subnode
''Nodeslength = objxmldom. documentelement. childnodes. Length
''Response. Write (nodeslength & "<br> ")
'Get the parent node object
'Set parentnodes = objxmldom. documentelement
Set parentnodes = objxmldom.doc umentelement. selectsinglenode ("// books ")
'Get the length of the subnode
Childnodeslength = parentnodes. childnodes. Length
'Length of the output subnode
Response. Write ("Number of subnodes:" & parentnodes. childnodes. length)
Response. Write ("<br> ")

'Traverse the attributes and nodes of the subnode
For I = 0 to childNodesLength-1
Set objchile = parentnodes. childnodes (I)

Response. Write (I + 1 & ": bookid =" & objchile. getattribute ("ID "))
Response. Write (", sortid =" & objchile. getattribute ("sortid "))
Response. Write (", Title =" & objchile. selectsinglenode ("title"). Text)
Response. Write (", author =" & objchile. selectsinglenode ("author"). Text)
Response. Write (", <a href =" "javascript: removechilenode (" & I & ")"> Delete </a> ")
Response. Write (", <a href =" "javascript: editchilenode (" & I & ")"> edit </a> <br> ")
Next
Set objxmldom = nothing
%>
<SCRIPT>
Function removechilenode (ID)
{
If (! Confirm ("are you sure you want to delete the" + ID + "data nodes? ") Return false;
Location. href = 'delxmlchildnode. asp? Id = '+ ID;
}
Function editchilenode (ID)
{
Location. href = 'editbook. asp? Id = '+ ID;
}
</SCRIPT>

Books. xml

<? XML version = "1.0" encoding = "gb2312"?>
<Books>
<Book id = "4" sortid = "A4">
<Title> author4aa </title>
<Author> author4 </author>
</Book>
<Book id = "5" sortid = "A5">
<Title> author55 </title>
<Author> author5 </author>
</Book>
<Book id = "6" sortid = "A6">
<Title> booktitle </title>
<Author> author6 </author>
</Book>
</Books>

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.