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

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.

XML
<VariableData>
  <Header>
    <ClientOrderNo>6001020177</ClientOrderNo>
    <EMail />
    <PONumber>52183426</PONumber>
    <RSNComment />
    <PONumber300>3004438655</PONumber300>
    <RSNPODate>20141210</RSNPODate>
  </Header>
  <Lines>
    <Line>
      <CustomerLineItemNo>000010</CustomerLineItemNo>
      <CustomerLineItemNoTrim>10</CustomerLineItemNoTrim>
      <PoLineItemNumber>000010</PoLineItemNumber>
      <SPSPartNumber>9506-PMXMESCC [PN-C41034]</SPSPartNumber>
      <SAPMaterialNumber />
      <RFF05LI />
      <RFF05SE />
      <MktNo />
      <Quantity ordered="20" />
      <RegisterTo>
        <ContactName />
        <Address1>TEVA PHARMACEUTICAL</Address1>
        <Address2>HA'GAVISH 5</Address2>
        <Address3 />
        <Address4 />
        <Address5>KFAR SABA 44102  IL</Address5>
      </RegisterTo>
      <PickHeaderId />
      <Installs>001</Installs>
      <SellingPrice>6633</SellingPrice>
      <Components>
        <Component>
          <ComponentItemNo>1</ComponentItemNo>
          <BomItemCount />
          <CustomerPartDecription>PMX MES Concurrent Client License</CustomerPartDecription>
          <ComponentPart>9506-PMXMESCC [PN-C41034]</ComponentPart>
          <Installs>1</Installs>
          <Revision>4.00.00</Revision>
          <LicenseType>N/A</LicenseType>
          <ActivationType>N/A</ActivationType>
          <LifeTimeExpiration>PERMANENT</LifeTimeExpiration>
          <Comments />
          <TermEndDate />
          <TermDays>0000</TermDays>
          <Comments />
          <RssType>N</RssType>
          <Platform>Y</Platform>                  
           
            <SerialDetail>
              <ComponentLineItemNo>18</ComponentLineItemNo>
              <SerialNumberRecord>18</SerialNumberRecord>
              <ProductKey>***********</ProductKey>
              <SerialNo>35000001</SerialNo>
            </SerialDetail>
            <SerialDetail>
              <ComponentLineItemNo>19</ComponentLineItemNo>
              <SerialNumberRecord>19</SerialNumberRecord>
              <ProductKey>***********</ProductKey>
              <SerialNo>35000001</SerialNo>
            </SerialDetail>
            <SerialDetail>
              <ComponentLineItemNo>20</ComponentLineItemNo>
              <SerialNumberRecord>20</SerialNumberRecord>
              <ProductKey>***********</ProductKey>
              <SerialNo>35000001</SerialNo>
            </SerialDetail>
          </SerialDetails>
        </Component>
      </Components>
      <Description>Concurrent Lic for any no of workstation</Description>
    </Line>
  </Lines>
  <Details>
    <OrderDate />
  </Details>
</VariableData>


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.
Posted
Updated 16-Feb-22 9:48am
v2

Quote:
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 :
XPath
/VariableData/Lines/Line/Components/Component/SerialDetails/SerialDetail/SerialNumberRecord
or
XPath
//SerialDetails/SerialDetail/SerialNumberRecord
 
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()
serverDoc.Load("YourXmlPath")
Dim xml As XmlNodeList = serverDoc.SelectNodes("/VariableData/Header")

For Each node As XmlNode In xml
    Dim ClientOrderNo = node.SelectSingleNode("ClientOrderNo").InnerText
Next
 
Share this answer
 
v2
Comments
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