Advertisement

06.08.2006 at 09:52AM PDT, ID: 21879658
[x]
Attachment Details

XPath Iterating through nodes with C#

Asked by SuperGhosty in Extensible Markup Language (XML)

Tags: xpath, xml, nodes, through, iterate

I'm using C# and reading an XML document like the following (example):

<it>
    <abc>123</abc>
    <stuff>0</stuff>
    <jumbo>
        <big>false</big>
        <large>true</large>
    </jumbo>
</it>

I'm using the xPathNavigator and xPathNodeIterator to go through each node. The problem is I don't always know what nodes will be in the <it> node. So I need a way to iterate through the nodes and just add the node name and value to an array. I've almost got it however when I use the xPathNodeIterator and search all descendants it returns "falsetrue" for the <jumbo> node - apparently reading the value of this node concatenates the two child node values.

Is there a way around this? I want to iterate through each node and return just the node name and value without adding an element that has child elements.Start Free Trial
[+][-]06.08.2006 at 03:59PM PDT, ID: 16866031

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 08:25PM PDT, ID: 16867249

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.09.2006 at 03:57AM PDT, ID: 16869216

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Extensible Markup Language (XML)
Tags: xpath, xml, nodes, through, iterate
Sign Up Now!
Solution Provided By: carl_tawn
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.09.2006 at 08:54AM PDT, ID: 16871407

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32