I am trying to pull information out of an XML String, but i am struggling looping through the nodes.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(OrderXml);
XmlNodeList parentNode = xmlDoc.GetElementsByTagName("SalesOrders");
XmlNodeList SalesOrderNode = xmlDoc.GetElementsByTagName("SalesOrder");
XmlNodeList parentNode2 = xmlDoc.GetElementsByTagName("WarningMessages");
foreach (XmlNode childrenNode in parentNode2)
{
string test = childrenNode.Value.ToString();
}
I would like to Grab SalesOrder number, in this case its r31283, After which i would like to loop through the contents of WarningMessages. I need to grab the line number and stock code for each warning description.
My XML:
<?xml version="1.0" encoding="Windows-1252"?>
<SalesOrders Language='05' Language2='EN' CssStyle='' DecFormat='1' DateFormat='01' Role='01' Version='6.1.085' OperatorPrimaryRole='100'>
<TransmissionHeader>
<TransmissionReference>00000000000003</TransmissionReference>
<SenderCode/>
<DatePrepared>2014-05-22</DatePrepared>
<TimePrepared>09:12</TimePrepared>
</TransmissionHeader>
<Order>
<CustomerPoNumber>RQ140522-33</CustomerPoNumber>
<SalesOrder>r31283</SalesOrder>
<OrderActionType>A</OrderActionType>
<BackOrderComment>One or more lines have been placed on back order for order 'r31283'</BackOrderComment>
<WarningMessages>
<WarningDescription>Line 0001 for stock code 'NN0410BP01' was placed on back order</WarningDescription>
<WarningDescription>Line 0002 for stock code 'NN0400GR08' was placed on back order</WarningDescription>
<WarningDescription>Line 0003 for stock code 'NN0410BN01' was placed on back order</WarningDescription>
<WarningDescription>Line 0004 for stock code 'NN0370BH01' was placed on back order</WarningDescription>
<WarningDescription>Line 0005 for stock code 'NN0370BH02' was placed on back order</WarningDescription>
<WarningDescription>Line 0006 for stock code 'NN0390BC01' was placed on back order</WarningDescription>
<WarningDescription>Line 0007 for stock code 'NN0410HL01' was placed on back order</WarningDescription>
<WarningDescription>Line 0008 for stock code 'NN0410FD07' was placed on back order</WarningDescription>
<WarningDescription>Line 0009 for stock code 'NN0410FD08' was placed on back order</WarningDescription>
<WarningDescription>Line 0010 for stock code 'NN0400VL02' was placed on back order</WarningDescription>
</WarningMessages>
</Order>
</SalesOrders>