Click here to Skip to main content
15,797,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have the below XML data that was created by BizTalk. I'm finding it hard to get specific values out of it. For instance, I'd like to get all ClientOrderNo, Address lines, ComponentPart, SerialNo.

Help would be great as I not great with XML.

    <EMail />
    <RSNComment />
      <SPSPartNumber>9506-PMXMESCC [PN-C41034]</SPSPartNumber>
      <SAPMaterialNumber />
      <RFF05LI />
      <RFF05SE />
      <MktNo />
      <Quantity ordered="20" />
        <ContactName />
        <Address1>TEVA PHARMACEUTICAL</Address1>
        <Address2>HA'GAVISH 5</Address2>
        <Address3 />
        <Address4 />
        <Address5>KFAR SABA 44102  IL</Address5>
      <PickHeaderId />
          <BomItemCount />
          <CustomerPartDecription>PMX MES Concurrent Client License</CustomerPartDecription>
          <ComponentPart>9506-PMXMESCC [PN-C41034]</ComponentPart>
          <Comments />
          <TermEndDate />
          <Comments />
      <Description>Concurrent Lic for any no of workstation</Description>
    <OrderDate />

What I have tried:

I've searched the web for examples, but no luck. None of the examples seem to fit what I'm looking for.
Updated 16-Feb-22 10:48am

None of the examples seem to fit what I'm looking for
The chances of you finding a sample that exactly matches your requirements or fairly low. You need to loo at the XmlReader Class (System.Xml) | Microsoft Docs[^]. It contains methods for iterating through all nodes, finding specific nodes etc.
Share this answer
There is no direct way of returning all required elements. However you can use XPath to get the deepest node(s) and then use node.parent method to read parent elements.

A simple XPath could be :
Share this answer
First <serialdetails> node is missing in your xml and secondly you can achieve through xPath like below code. i had implemented one for you and other xPaths you can define
Dim serverDoc As XmlDocument = New XmlDocument()
Dim xml As XmlNodeList = serverDoc.SelectNodes("/VariableData/Header")

For Each node As XmlNode In xml
    Dim ClientOrderNo = node.SelectSingleNode("ClientOrderNo").InnerText
Share this answer
CHill60 16-Feb-22 12:45pm    
You've implemented this in C# but the question is tagged VB
M Imran Ansari 16-Feb-22 13:02pm    
Improved my answer with VB. Thanks for pointing out. :)

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