Microsoft
Software
Hardware
Network
Question : Loop through XML file using VB.Net
Hi Guys
Below is a sample of an XML file
<?xml version="1.0" encoding="UTF-8" ?>
<DsOrders xmlns="
http://www.tempuri.
org/DsOrde
rInfo.xsd
"
>
<Orders>
<OrderID>WEB201006293</Ord
erID>
<Company></Company>
<DelContactName>maria barrett</DelContactName>
<DelCompany></DelCompany>
<DelAddress1>23 buttermere close</DelAddress1>
<DelAddress2></DelAddress2
>
<DelCounty>kent</DelCounty
>
<DelPostCode>ME7 2TS</DelPostCode>
<DelTown>gillingham</DelTo
wn>
<DelCountry>GB</DelCountry
>
<OrderDate>2010-06-29 09:25:40</OrderDate>
<Carriage>1.2766</Carriage
>
<CarriageTaxCode>1</Carria
geTaxCode>
<tax>1.93</tax>
<DelEmail>barrettmaria@hot
mail.com</
DelEmail>
<DelTel>07800937785</DelTe
l>
<DelFax></DelFax>
<AddressType>R</AddressTyp
e>
<CustomerType>Personal use</CustomerType>
<TutorNo></TutorNo>
<PaymentRef>WEB201006293</
PaymentRef
>
<Payment>14.49</Payment>
<PaymentType>SR</PaymentTy
pe>
<BankPostingCode>1201</Ban
kPostingCo
de>
<CarriageNominalCode>4401<
/CarriageN
ominalCode
>
</Orders>
<Orders>
<OrderID>WEB201006295</Ord
erID>
<Company></Company>
<DelContactName>Neil Hart</DelContactName>
<DelCompany></DelCompany>
<DelAddress1>Flat 2 Lansdowne Court</DelAddress1>
<DelAddress2>25 Lansdowne Road</DelAddress2>
<DelCounty>East Sussex</DelCounty>
<DelPostCode>BN3 1GB</DelPostCode>
<DelTown>Hove</DelTown>
<DelCountry>GB</DelCountry
>
<OrderDate>2010-06-29 10:30:29</OrderDate>
<Carriage>1.50</Carriage>
<CarriageTaxCode>0</Carria
geTaxCode>
<tax>0.00</tax>
<DelEmail>
[email protected]
<
/DelEmail>
<DelTel>07989107285</DelTe
l>
<DelFax></DelFax>
<AddressType>R</AddressTyp
e>
<CustomerType></CustomerTy
pe>
<TutorNo></TutorNo>
<PaymentRef>WEB201006295</
PaymentRef
>
<Payment>8.00</Payment>
<PaymentType>SR</PaymentTy
pe>
<BankPostingCode>1201</Ban
kPostingCo
de>
<CarriageNominalCode>4401<
/CarriageN
ominalCode
>
</Orders>
<Orders>
<OrderID>WEB201006296</Ord
erID>
<Company></Company>
<DelContactName>Lydia Jarvis</DelContactName>
<DelCompany></DelCompany>
<DelAddress1>2 Edward Street</DelAddress1>
<DelAddress2>Trecynon</Del
Address2>
<DelCounty>R.C.T</DelCount
y>
<DelPostCode>CF44 8LW</DelPostCode>
<DelTown>Aberdare</DelTown
>
<DelCountry>GB</DelCountry
>
<OrderDate>2010-06-29 10:45:54</OrderDate>
<Carriage>1.50</Carriage>
<CarriageTaxCode>0</Carria
geTaxCode>
<tax>0.00</tax>
<DelEmail>lyddiej@hotmail.
com</DelEm
ail>
<DelTel>01685874500</DelTe
l>
<DelFax></DelFax>
<AddressType>R</AddressTyp
e>
<CustomerType></CustomerTy
pe>
<TutorNo></TutorNo>
<PaymentRef>WEB201006296</
PaymentRef
>
<Payment>14.50</Payment>
<PaymentType>SR</PaymentTy
pe>
<BankPostingCode>1201</Ban
kPostingCo
de>
<CarriageNominalCode>4401<
/CarriageN
ominalCode
>
</Orders>
<Orders>
<OrderID>WEB201006296</Ord
erID>
<Company></Company>
<DelContactName>Lydia Jarvis</DelContactName>
<DelCompany></DelCompany>
<DelAddress1>2 Edward Street</DelAddress1>
<DelAddress2>Trecynon</Del
Address2>
<DelCounty>R.C.T</DelCount
y>
<DelPostCode>CF44 8LW</DelPostCode>
<DelTown>Aberdare</DelTown
>
<DelCountry>GB</DelCountry
>
<OrderDate>2010-06-29 10:45:54</OrderDate>
<Carriage>1.50</Carriage>
<CarriageTaxCode>0</Carria
geTaxCode>
<tax>0.00</tax>
<DelEmail>lyddiej@hotmail.
com</DelEm
ail>
<DelTel>01685874500</DelTe
l>
<DelFax></DelFax>
<AddressType>R</AddressTyp
e>
<CustomerType></CustomerTy
pe>
<TutorNo></TutorNo>
<PaymentRef>WEB201006296</
PaymentRef
>
<Payment>14.50</Payment>
<PaymentType>SR</PaymentTy
pe>
<BankPostingCode>1201</Ban
kPostingCo
de>
<CarriageNominalCode>4401<
/CarriageN
ominalCode
>
</Orders>
<OrderItems>
<OrderID>WEB201006293</Ord
erID>
<ProductCode>SOC10250W</Pr
oductCode>
<Description>Hello Mr Tumble! DVD</Description>
<Quantity>1</Quantity>
<Price>11.06</Price>
<TaxCode>1</TaxCode>
</OrderItems>
<OrderItems>
<OrderID>WEB201006295</Ord
erID>
<ProductCode>DLR01040W</Pr
oductCode>
<Description>Pocket book of signs 1</Description>
<Quantity>1</Quantity>
<Price>6.5</Price>
<TaxCode>0</TaxCode>
</OrderItems>
<OrderItems>
<OrderID>WEB201006296</Ord
erID>
<ProductCode>DLR02040W</Pr
oductCode>
<Description>Pocket book of signs 2</Description>
<Quantity>1</Quantity>
<Price>6.5</Price>
<TaxCode>0</TaxCode>
</OrderItems>
<OrderItems>
<OrderID>WEB201006296</Ord
erID>
<ProductCode>DLR01040W</Pr
oductCode>
<Description>Pocket book of signs 1</Description>
<Quantity>1</Quantity>
<Price>6.5</Price>
<TaxCode>0</TaxCode>
</OrderItems>
</DsOrders>
What I would like to do is loop through the data where the data is between <Orders> and </Orders>
I would then like to show distinct orders based on <OrderID> </OrderID>
As you can see there are 2 orders with the same OrderID <OrderID>WEB201006296</Ord
erID>
I only need to process the one Order.
Then I would like to loop through where the data is between the Tags <OrderItems> and </OrderItems>
I am able to import xml file and process all the data but I am stuck.
Here is my code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Me.TextBox1.Text = ""
Dim rd As XmlReader = XmlReader.Create("c:\order
import2.xm
l")
While rd.Read
Select Case rd.NodeType
Case XmlNodeType.Element
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<{0}>", rd.Name) & ControlChars.NewLine
Case XmlNodeType.Text
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format(rd.Value) & ControlChars.NewLine
Case XmlNodeType.CDATA
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<![CDATA[{0
}]]>", rd.Value) & ControlChars.NewLine
Case XmlNodeType.ProcessingInst
ruction
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<?{0} {1}?>", rd.Name, rd.Value) & ControlChars.NewLine
Case XmlNodeType.Comment
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<!--{0}-->"
, rd.Value) & ControlChars.NewLine
Case XmlNodeType.XmlDeclaration
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<?xml version='1.0'?>") & ControlChars.NewLine
Case XmlNodeType.Document
Case XmlNodeType.DocumentType
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<!DOCTYPE {0} [{1}]", rd.Name, rd.Value) & ControlChars.NewLine
Case XmlNodeType.EntityReferenc
e
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format(rd.Name) & ControlChars.NewLine
Case XmlNodeType.EndElement
Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("</{0}>", rd.Name) & ControlChars.NewLine
End Select
End While
rd.Close()
End Sub
Any help please
Answer : Loop through XML file using VB.Net
you can use dataset.readxml command to read XML and then you easily fire a loop in a table or dataset or you can have the Select Distinct records from the dataset or datatable
Random Solutions
Passing combobox var to loaded swf as3
Create linked server from MS Sql to oracle server
Use .NET or SSIS to download Exhange email and process attachments
asp.net: How to determine if a when a user login. is an Admin Account, * the menu is selected to show admin pages & reports.
Strange DNS resolution
With regards to correlated subqueries does anybody know what the logical query processing order?
Validate month and year fields based on current date
Does OpenOffice allow Windows 7 preview pane to preview .doc and .xls files?
OWA idle time in Exchange 2010
How do I update my tables in mysql to include new data?