Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looping through XML file using VB.NET

I am having a problem processing an XMl file. I want to loop through (using VB.NET) the file and extract all the values of the OrderID element.

<?xml version="1.0"?>
<ListOrdersResponse xmlns="https://xxx.xxxxxx.com/Orders/999uuu777">
  <ListOrdersResult>
    <NextToken>XXXXXXXXXX</NextToken>
    <Orders>
      <Order>
        <ShipmentServiceLevelCategory>Standard</ShipmentServiceLevelCategory>
        <OrderId>ooooooooo</OrderId>
      </Order>
      <Order>
        <ShipmentServiceLevelCategory>Standard</ShipmentServiceLevelCategory>
        <OrderId>ujuujujuj</OrderId>
      </Order>
      </Orders>
    <CreatedBefore>2013-06-19T09:10:47Z</CreatedBefore>
  </ListOrdersResult>
  <ResponseMetadata>
    <RequestId>8e34f7d9-3af7-4490-801b-cccc7777yu</RequestId>
  </ResponseMetadata>
</ListOrdersResponse>

Here is the code I am trying but it does not loop through each order

Dim doc As New XmlDocument()
doc.Load(file)
Dim nodelist As XmlNodeList = doc.SelectNodes(".//Orders/Order")
For Each node As XmlElement In nodelist
   console.writeline(node.SelectSingleNode("OrderID").InnerText)
Next

Any help would be gratefully appreciated.

like image 906
user2516387 Avatar asked Jun 24 '13 13:06

user2516387


1 Answers

Try this:

doc.Load(file)
nodelist = doc.GetElementsByTagName("Order")

For Each node As XmlElement In nodelist
   Console.Writeline(node("OrderID").InnerText)
Next
like image 198
SysDragon Avatar answered Oct 23 '22 11:10

SysDragon