Hi,
Here is my xml:
Here is the code that reads the XML:
What I am finding is that as I am iterating through the orders node looking at each order. When I get the values stored in the child nodes Product as an example. It seems to go through all of the Product nodes in all of the orders each time it loops through. What I wanted was to get the Product values belonging to its respective order.
Does anyone know where I am going wrong?
If so please help, cheers, Dave.
Here is my xml:
Code:
<Orders>
<Header>
<CompanyGUID>026b518c-6916-434a-85ba-88fedce62fac</CompanyGUID>
<API_Version>1</API_Version>
</Header>
<Order SONumber= "123456">
<OrderConfiguration>
<StockStatus>Wait</StockStatus>
<CanBeQueued>True</CanBeQueued>
</OrderConfiguration>
<Product>
<QuickLinx>123YY</QuickLinx>
<Quantity>4</Quantity>
<Price>99.99</Price>
</Product>
<Address>
<BusinessName>A made up name</BusinessName>
<HouseNoAndStreetName>2 Made Up Street</HouseNoAndStreetName>
<Town>Bolton</Town>
<PostCode>BL11BL</PostCode>
</Address>
<Carriage>
<CarriageType>4</CarriageType>
</Carriage>
</Order>
<Order SONumber= "876543">
<OrderConfiguration>
<StockStatus>Line</StockStatus>
<CanBeQueued>False</CanBeQueued>
</OrderConfiguration>
<Product>
<QuickLinx>122WW</QuickLinx>
<Quantity>2</Quantity>
<Price>9.99</Price>
</Product>
<Address>
<BusinessName>Another made up name</BusinessName>
<HouseNoAndStreetName>55 Made Up Street</HouseNoAndStreetName>
<Town>Bolton</Town>
<PostCode>BL22BL</PostCode>
</Address>
<Carriage>
<CarriageType>3</CarriageType>
</Carriage>
</Order>
<Order SONumber= "123789">
<OrderConfiguration>
<StockStatus>Wait</StockStatus>
<CanBeQueued>True</CanBeQueued>
</OrderConfiguration>
<Product>
<QuickLinx>12WW</QuickLinx>
<Quantity>66</Quantity>
<Price>699.99</Price>
</Product>
<Address>
<BusinessName>Another made up name</BusinessName>
<HouseNoAndStreetName>233 Made Up Street</HouseNoAndStreetName>
<Town>Bolton</Town>
<PostCode>BL55BL</PostCode>
</Address>
<Carriage>
<CarriageType>32</CarriageType>
</Carriage>
</Order>
</Orders>
Here is the code that reads the XML:
Code:
Dim ordersXMLNodelst As XmlNodeList = order.SelectNodes("//Orders")
For Each ordersXMLItem As XmlNode In ordersXMLNodelst
Order loop:
Dim orderXMLNodelst As XmlNodeList = order.SelectNodes("//Order")
For Each orderXMLItem As XmlNode In orderXMLNodelst
If orderXMLItem.Attributes("SONumber") IsNot Nothing Then
Create local variables to hold order details:
Customers Sales order number
Dim custSalesOrderNo As Int32 = Convert.ToInt32(orderXMLItem.Attributes("SONumber").InnerXml)
Order configuration
Dim stockStatus As String = String.Empty
Dim canBeQueued As Boolean = True
Product
Dim QuickLinx As String = String.Empty
Dim Quantity As Int32 = 0
Dim Price As Decimal = 0
Address
Dim BusinessName As String = String.Empty
Dim HouseNoAndStreetName As String = String.Empty
Dim Town As String = String.Empty
Dim PostCode As String = String.Empty
Carriage
Dim CarriageType As Int32 = 0
Build the individual order up:
Get the order configuration
Dim orderConfigurationXMLNodelst As XmlNodeList = order.SelectNodes("//OrderConfiguration")
For Each orderConfigurationXMLItem As XmlNode In orderConfigurationXMLNodelst
stockStatus = orderConfigurationXMLItem.SelectSingleNode("StockStatus").InnerXml()
canBeQueued = Convert.ToBoolean(orderConfigurationXMLItem.SelectSingleNode("CanBeQueued").InnerXml())
Next
Get the product information
Dim productXMLNodelst As XmlNodeList = order.SelectNodes("//Product")
For Each productXMLItem As XmlNode In productXMLNodelst
QuickLinx = productXMLItem.SelectSingleNode("QuickLinx").InnerXml()
Quantity = Convert.ToInt32(productXMLItem.SelectSingleNode("Quantity").InnerXml())
Price = Convert.ToDecimal(productXMLItem.SelectSingleNode("Price").InnerXml())
Next
Get the address information
Dim addressXMLNodelst As XmlNodeList = order.SelectNodes("//Address")
For Each addressXMLItem As XmlNode In addressXMLNodelst
BusinessName = addressXMLItem.SelectSingleNode("BusinessName").InnerXml()
HouseNoAndStreetName = addressXMLItem.SelectSingleNode("HouseNoAndStreetName").InnerXml()
Town = addressXMLItem.SelectSingleNode("Town").InnerXml()
PostCode = addressXMLItem.SelectSingleNode("PostCode").InnerXml()
Next
Get the carriage information
Dim carriageXMLNodelst As XmlNodeList = order.SelectNodes("//Carriage")
For Each carriageXMLItem As XmlNode In carriageXMLNodelst
CarriageType = Convert.ToInt32(carriageXMLItem.SelectSingleNode("CarriageType").InnerXml())
Next
Call middle tier to place the order
Dim middleTier As New MiddleTier
Dim salesOrder As Int32 = 0
salesOrder = middleTier.placeOrder(stockStatus, canBeQueued, QuickLinx, Quantity, Price, BusinessName, HouseNoAndStreetName, Town, PostCode, CarriageType)
Else
orderDetails = "-1"
End If
Next
Next
What I am finding is that as I am iterating through the orders node looking at each order. When I get the values stored in the child nodes Product as an example. It seems to go through all of the Product nodes in all of the orders each time it loops through. What I wanted was to get the Product values belonging to its respective order.
Does anyone know where I am going wrong?
If so please help, cheers, Dave.