Wrox Programmer Forums
|
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2005, 06:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml looping problem

Hopefully somebody can help me with this. I am using the USPS API, and get the following results, as you can see it is repeating the Postage twice. I am not sure what I am doing wrong. I have used this same code on the other API's and it works perfectly. Could it be something to do with the way I am looping thru the Postage Node? Is this correct or is there a better way?

XML_________
<Package ID="0">
    <ZipOrigination></ZipOrigination>
    <ZipDestination></ZipDestination>
    <Postage>
    <MailService></MailService>
    <Rate></Rate>
    </Postage>
<Package>

RESULTS_____________
4--childnode length
0--j
Zipcode Origination: 10022
1--j
Zipcode Destination: 20008
2--j
Postage:
Mail Service: Priority Mail Flat Rate Box (11.25" x 8.75" x 6")
Rate: 7.70
Mail Service: Priority Mail Flat Rate Box (14" x 12" x 3.5")
Rate: 7.70
3--j
Postage:
Mail Service: Priority Mail Flat Rate Box (11.25" x 8.75" x 6")
Rate: 7.70
Mail Service: Priority Mail Flat Rate Box (14" x 12" x 3.5")
Rate: 7.70

CODE_____________
set xmlDoc = createobject("MSXML.DOMDocument")

xmlDoc.validateOnParse = False
xmlDoc.loadXML (resp)

Set nodeList = xmlDoc.getElementsByTagName("Package")
For i = 0 To nodeList.length-1
Set n = nodeList.Item(i)
Response.Write n.childNodes.length & "--childnode length<BR>"

For j = 0 To n.childNodes.length-1
Response.Write j & "--j<BR>"
Set e = n.childNodes.Item(j)

Select Case e.NodeName
Case "ZipOrigination"
    Response.Write "Zipcode Origination: " & e.firstChild.nodeValue & "<br />"
Case "ZipDestination"
    Response.Write "Zipcode Destination: " & e.firstChild.nodeValue & "<br />"
Case "Postage"
    Response.Write "Postage: <br />"

    Set nodeList2 = xmlDoc.getElementsByTagName(e.NodeName)
    For l = 0 To nodeList2.length - 1
    Set m = nodeList2.Item(l)

    For p = 0 To m.childNodes.length - 1
    Set r = m.childNodes.Item(p)
    If r.nodeName = "MailService" Then
    Response.Write "Mail Service: " & r.firstChild.nodeValue & "<br />"
    ElseIf r.nodeName = "Rate" Then
    Response.Write "Rate: " & r.firstChild.nodeValue & "<br />"
    Else
    'error
    End If
    Next
    Next

End Select
Next
Next

Thank You In Advance
__________________
Peace
Mike
http://www.eclecticpixel.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through a list using logic tags problem aadz5 Struts 3 September 23rd, 2011 03:18 AM
Looping through XML li72 XSLT 2 February 20th, 2008 12:13 PM
Problem with repeat data in XML to XML transformat tslag XSLT 4 June 13th, 2006 08:45 AM
Looping through XML in SQL Server 2005 francislang SQL Server 2005 1 February 23rd, 2006 11:47 AM
Looping through attributes in an XML document francislang XML 4 November 17th, 2004 11:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.