troubleshooting Question

XML & C# challenge - #4

Avatar of teknovation
teknovation asked on
XMLC#.NET Programming
11 Comments1 Solution130 ViewsLast Modified:
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>

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>
ASKER CERTIFIED SOLUTION
Dmitry G
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros