troubleshooting Question

XML node Challenge 3

Avatar of teknovation
teknovation asked on
XMLC#.NET Programming
19 Comments1 Solution194 ViewsLast Modified:
All,

If there are two similar parent node or tag - which in this case is Address, the only difference is the first Address tag is meant for SHIP to address which is showned in the <AddressTypeCode> with value of "ST" and BILL TO address shown with "BT" value. How can I extract the tags based on the <AddressTypeCode> value?

If <AddressTypeCode> child tag in the <Address> parent tag equals ST= then show like this:

The ship to address is: Pepsi Distribution Center, ABC 123, Safeway 7th Street, Suite 1, Detroit, MI, 12345, USA
If <AddressTypeCode> child tag in the <Address> parent tag equals BT= then show like this:
The bill to address is: Main Headquarters, Attn: John, 147 Dupont Ave, Dock 123, Orlando, FL, 12345, USA

XML Code:
<?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>
		</Header>


C# code: My attempt to write it
 // Ship to Address  
                        var addresses = xdoc.XPathSelectElements("//testinc:Address", nsmgr);//Get all the address childs : 2 in this case 
                        List<string> listofAddresses = new List<string>();//List to store the addresses 
                        foreach (XElement address in addresses)//For each line item
                        { 
                             //something here?
                        }
ASKER CERTIFIED SOLUTION
Karrtik Iyer
Software Architect

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 19 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 19 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