Click here to Skip to main content
15,907,396 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,
I could really do with some help here. I know f all about xml and I need to do something with xml. Below you will see the XML content. I need to read the following

CustomerPartDescription
ComponentPart
Product Key
SerialNo

The below xml has only one part on it but there could be mutiple parts with their own product key and serialno in the xml file.
Please if anyone has time could they help taking into account I know more than little about XML

<?xml version="1.0" encoding="UTF-16"?>
<OrderLoadData>
<VariableData>
<VariableData>
<Header>
<ClientOrderNo>6504271201</ClientOrderNo>
<EMail/>
<PONumber>J071.3.5.0.26698</PONumber>
<RSNComment/>
<PONumber300>3007557587</PONumber300>
<RSNPODate>20190111</RSNPODate>
</Header>
<Lines>
<Line>
<CustomerLineItemNo>000010</CustomerLineItemNo>
<CustomerLineItemNoTrim>10</CustomerLineItemNoTrim>
<PoLineItemNumber>000010</PoLineItemNumber>
<SPSPartNumber>9527-I5PRLUSBINTM [PN-516445]</SPSPartNumber>
<SAPMaterialNumber/>
<RFF05LI/>
<RFF05SE/>
<MktNo/>
<Quantity ordered="5"/>
<CountryOfOrigin>CA</CountryOfOrigin>
<pre><?xml version="1.0" encoding="UTF-16"?>
<OrderLoadData>
<VariableData>
<VariableData>
<Header>
<ClientOrderNo>6504271201</ClientOrderNo>
<EMail/>
<PONumber>J071.3.5.0.26698</PONumber>
<RSNComment/>
<PONumber300>3007557587</PONumber300>
<RSNPODate>20190111</RSNPODate>
</Header>
<Lines>
<Line>
<CustomerLineItemNo>000010</CustomerLineItemNo>
<CustomerLineItemNoTrim>10</CustomerLineItemNoTrim>
<PoLineItemNumber>000010</PoLineItemNumber>
<SPSPartNumber>9527-I5PRLUSBINTM [PN-516445]</SPSPartNumber>
<SAPMaterialNumber/>
<RFF05LI/>
<RFF05SE/>
<MktNo/>
<Quantity ordered="5"/>
<CountryOfOrigin>CA</CountryOfOrigin>
<RegisterTo>
<ContactName/>
<Address1>JON DOE</Address1>
<Address2>Timbucktwo</Address2>
<Address3/>
<Address4/>
<Address5>Earth</Address5>
</RegisterTo>
<PickHeaderId/>
<Installs>001</Installs>
<SellingPrice>18</SellingPrice>
<Components>
<Component>
<ComponentItemNo>1</ComponentItemNo>
<BomItemCount/>
<CustomerPartDecription>ISaGRAF5 Essential Unlimited USB MED S/W</CustomerPartDecription>
<ComponentPart>9527-I5PRLUSBINTM [PN-516445]</ComponentPart>
<Installs>1</Installs>
<Revision>5.22.00</Revision>
<LicenseType>N/A</LicenseType>
<ActivationType>NP</ActivationType>
<LifeTimeExpiration>PERMANENT</LifeTimeExpiration>
<Comments/>
<TermEndDate/>
<TermDays>0000</TermDays>
<Comments/>
<RssType>N</RssType>
<Platform>Y</Platform>
<SerialDetails>
<SerialDetail>
<ComponentLineItemNo>1</ComponentLineItemNo>
<SerialNumberRecord>1</SerialNumberRecord>
<ProductKey>RRRRRRR</ProductKey>
<SerialNo>OOOOOOO</SerialNo>
</SerialDetail>
<SerialDetail>
<ComponentLineItemNo>2</ComponentLineItemNo>
<SerialNumberRecord>2</SerialNumberRecord>
<ProductKey>PPPPPPP</ProductKey>
<SerialNo>UUUUUUU</SerialNo>
</SerialDetail>
<SerialDetail>
<ComponentLineItemNo>3</ComponentLineItemNo>
<SerialNumberRecord>3</SerialNumberRecord>
<ProductKey>NNNNNNN</ProductKey>
<SerialNo>QQQQQQQ</SerialNo>
</SerialDetail>
<SerialDetail>
<ComponentLineItemNo>4</ComponentLineItemNo>
<SerialNumberRecord>4</SerialNumberRecord>
<ProductKey>DDDDDDD</ProductKey>
<SerialNo>WWWWWWW</SerialNo>
</SerialDetail>
<SerialDetail>
<ComponentLineItemNo>5</ComponentLineItemNo>
<SerialNumberRecord>5</SerialNumberRecord>
<ProductKey>YYYYYYY</ProductKey>
<SerialNo>XXXXXXX</SerialNo>
</SerialDetail>
</SerialDetails>
</Component>
</Components>
<Description>ISaGRAF5 Essential Unlimited USB MED S/W</Description>
</Line>
</Lines>
<Details>
<OrderDate/>
</Details>
</VariableData>
</VariableData>
</OrderLoadData>


What I have tried:

Searched web but not sure how to use what I found
Posted
Updated 14-Jan-19 5:36am

1 solution

You can do it in few ways, through:
1) XDocument class[^]
2) XmlDocument class[^]
3) XmlSerialization[^]

For further details, please see:
Parsing XML (Visual Basic) | Microsoft Docs[^]
HOW TO: Read XML Data into a DataSet by Using Visual Basic .NET[^]
How to: Access XML Descendant Elements (Visual Basic) | Microsoft Docs[^]

Example:
VB.NET
Dim xdoc As XDocument = XDocument.Load("FullFileNameHere.xml")
	Dim myData = xdoc.Descendants("Component") _
		.Select(Function(x) New With _
			{ _
				.CustomerPartDescription = x.Element("CustomerPartDecription").Value, _
				.ComponentPart = x.Element("ComponentPart").Value, _
				.ProductKey = x.Descendants("SerialDetail").Select(Function(y) y.Element("ProductKey").Value).ToList(), _
				.SerialNo = x.Descendants("SerialDetail").Select(Function(y) y.Element("SerialNo").Value).ToList() _
			})

Returns:

CustomerPartDescription                      ComponentPart             ProductKey SerialNo
ISaGRAF5 Essential Unlimited USB MED S/W     9527-I5PRLUSBINTM [PN-516445]     RRRRRRR     OOOOOOO
                                                                               PPPPPPP     UUUUUUU
                                                                               NNNNNNN     QQQQQQQ
                                                                               DDDDDDD     WWWWWWW     
                                                                               YYYYYYY     XXXXXXX
 
Share this answer
 
Comments
johnjsm 14-Jan-19 12:19pm    
ok. Output looks great but how do I get it. I'm sorry. Fighting a bug at the moment and head is fried.
Maciej Los 14-Jan-19 13:39pm    
Read my answer carefully.
johnjsm 15-Jan-19 5:49am    
I have and to some degree I understand but at same time this is so much more advanced than my skills. Sorry
Maciej Los 15-Jan-19 6:05am    
Well, no one expecting from you that you become an expert in few seconds. Please, follow the links provided in my answer and you'll find a method which will be more acurate to your skills. Don't give up! And never say sorry again in such of situation.
johnjsm 15-Jan-19 6:51am    
Thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900