Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 18th, 2005, 06:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:44 AM.


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