Link to home
Start Free TrialLog in
Avatar of Kevin Cabral
Kevin Cabral

asked on

Get Multiple Elements on the same Leaf

Hello,

I have some XML
<exhibitor>
                     <primary_key/>
                     <company_name></company_name>
                     <state></state>
                     <zip></zip>
                     <country_code></country_code>
                     <contact>
                        <first_name></first_name>
                        <last_name></last_name>
                        <credentials/>
                        <phone/>
                        <phone_ext/>
                     </contact>
                  </exhibitor>
I Am trying to using XPath get the primary key and contact elements while keeping them in the exhibitor root node?

XmlNodeList ExhibitorNodes2 = ExhibitorsNode2.SelectNodes("exhibitor/*[self::key_id or self::contact]");

this is just separating them and giving me the key_id and contact as a list i want them to stay in their exhibitor root?
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

I do not really understand what you want to achieve?

If you have a key_id element (primary_key ?) and contacts elements you my navigate to a root from them.

If you want some new structure you need to copy elements and link them.
Avatar of Kevin Cabral
Kevin Cabral

ASKER

As it is now this XMLNodeList will return me primary_key, contact, primary_key, contact; I would like to rip it while keeping it in its top level exhibitor, that way the XMLNodeList is a list of exhibitors with the information inside.
You have shown us what the XML document looks like before, can you now show us what you want the result of manipulation to look like.

Also does it need to be using XPath and XmlDocument objects or are you open to Linq to XML?
<exhibitor>
                     <primary_key/>
                        <first_name></first_name>
                        <last_name></last_name>
                        <credentials/>
                        <phone/>
                        <phone_ext/>
                  </exhibitor>

this is my end goal with what was in contact being essentially out, I'm open to anything although I am working in a .net environment at this point so  as long as i can pull of what i need to there i'm good.

Once i have something in the node list i'm using a set of libraries we have here internally at my place to Fill Data From XML to a dictionary then load it into SQL.
SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial