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
|