Avatar of teknovation
teknovation

asked on 

XML & C# challenge - #4

All - can someone tell me how to achieve this? Here's the background:

There are multiple <Notes> tag but only want the one inside the <Header> (see the image for a clearer illustration of this). Then I want to concatenate the two notes tag into one sentence.

For instance, the output should be:
This is the first note. This is the second note.

Thanks in advance!

XML File:
<?xml version="1.0" encoding="UTF-8"?>
<Orders xmlns="www.test-inc.com">
  <Order>
    <Header>
      <Address>
        <AddressTypeCode>ST</AddressTypeCode>
        <LocationCodeQualifier>51</LocationCodeQualifier>
        <AddressName>Pepsi Distribution Center</AddressName>
        <AddressAlternateName>ABC 123</AddressAlternateName>
        <Address1>Safeway 7th Street</Address1>
        <Address2>Suite 1</Address2>
        <City>Detroit</City>
        <State>MI</State>
        <PostalCode>12345</PostalCode>
        <Country>USA</Country>
      </Address>
      <Address>
        <AddressTypeCode>BT</AddressTypeCode>
        <LocationCodeQualifier>51</LocationCodeQualifier>
        <AddressLocationNumber>15513432</AddressLocationNumber>
        <AddressName>Main Headquarters</AddressName>
        <AddressAlternateName>Attn: John</AddressAlternateName>
        <Address1>147 Dupont Ave</Address1>
        <Address2>Dock 123</Address2>
        <City>Orlando</City>
        <State>FL</State>
        <PostalCode>12345</PostalCode>
        <Country>USA</Country>
        <Contact>
          <ContactTypeCode>BD</ContactTypeCode>
          <ContactName>Jane Doe</ContactName>
          <PrimaryPhone>111-222-3333</PrimaryPhone>
          <PrimaryFax>111-222-3333</PrimaryFax>
          <PrimaryEmail>buyer@TEST.com</PrimaryEmail>
        </Contact>
      </Address>
       <Notes>
          <NoteCode>TEST</NoteCode>
          <NoteField>This is the first note</NoteField>
      </Notes>
      <Notes>
          <NoteCode>TEST2</NoteCode>
          <NoteField>This is the second note</NoteField>
      </Notes>
   </Header>
    <LineItems> 
      <LineItem>
        <OrderLine>
          <LineItemSequenceNumber>1</LineItemSequenceNumber>
          <PartNumber>000AD001282</PartNumber>
          <PartName>Glaze Donut</PartName>
          <Notes> Item 1</Notes>
        </OrderLine>
      </LineItem>

      <LineItem>
        <OrderLine>
          <LineItemSequenceNumber>2</LineItemSequenceNumber>
          <PartNumber>0020001DS391</PartNumber>
          <PartName>Chocolate Donut</PartName>
          <Notes> Item 2</Notes>
        </OrderLine>
      </LineItem>

      <LineItem
        <OrderLine>
          <LineItemSequenceNumber>3</LineItemSequenceNumber>
          <PartNumber>000001SDF482</PartNumber>
          <PartName>Cherry Donut</PartName>
          <Notes> Item 3</Notes>
          <OrderLine>
      </LineItem>
   </LineItems> 
    
    <Summary>
      <TotalLineItemNumber>3</TotalLineItemNumber>
   </Summary>

  </Order>

Open in new window


xml.png
<?xml version="1.0" encoding="UTF-8"?>
<Orders xmlns="www.test-inc.com">
  <Order>
    <Header>
      <Address>
        <AddressTypeCode>ST</AddressTypeCode>
        <LocationCodeQualifier>51</LocationCodeQualifier>
        <AddressName>Pepsi Distribution Center</AddressName>
        <AddressAlternateName>ABC 123</AddressAlternateName>
        <Address1>Safeway 7th Street</Address1>
        <Address2>Suite 1</Address2>
        <City>Detroit</City>
        <State>MI</State>
        <PostalCode>12345</PostalCode>
        <Country>USA</Country>
      </Address>
      <Address>
        <AddressTypeCode>BT</AddressTypeCode>
        <LocationCodeQualifier>51</LocationCodeQualifier>
        <AddressLocationNumber>15513432</AddressLocationNumber>
        <AddressName>Main Headquarters</AddressName>
        <AddressAlternateName>Attn: John</AddressAlternateName>
        <Address1>147 Dupont Ave</Address1>
        <Address2>Dock 123</Address2>
        <City>Orlando</City>
        <State>FL</State>
        <PostalCode>12345</PostalCode>
        <Country>USA</Country>
        <Contact>
          <ContactTypeCode>BD</ContactTypeCode>
          <ContactName>Jane Doe</ContactName>
          <PrimaryPhone>111-222-3333</PrimaryPhone>
          <PrimaryFax>111-222-3333</PrimaryFax>
          <PrimaryEmail>buyer@TEST.com</PrimaryEmail>
        </Contact>
      </Address>
       <Notes>
          <NoteCode>TEST</NoteCode>
          <NoteField>This is the first note</NoteField>
      </Notes>
      <Notes>
          <NoteCode>TEST2</NoteCode>
          <NoteField>This is the second note</NoteField>
      </Notes>
   </Header>
    <LineItems> 
      <LineItem>
        <OrderLine>
          <LineItemSequenceNumber>1</LineItemSequenceNumber>
          <PartNumber>000AD001282</PartNumber>
          <PartName>Glaze Donut</PartName>
          <Notes> Item 1</Notes>
        </OrderLine>
      </LineItem>

      <LineItem>
        <OrderLine>
          <LineItemSequenceNumber>2</LineItemSequenceNumber>
          <PartNumber>0020001DS391</PartNumber>
          <PartName>Chocolate Donut</PartName>
          <Notes> Item 2</Notes>
        </OrderLine>
      </LineItem>

      <LineItem
        <OrderLine>
          <LineItemSequenceNumber>3</LineItemSequenceNumber>
          <PartNumber>000001SDF482</PartNumber>
          <PartName>Cherry Donut</PartName>
          <Notes> Item 3</Notes>
          <OrderLine>
      </LineItem>
   </LineItems> 
    
    <Summary>
      <TotalLineItemNumber>3</TotalLineItemNumber>
   </Summary>

  </Order>

Open in new window

XMLC#.NET Programming

Avatar of undefined
Last Comment
teknovation

8/22/2022 - Mon