Click here to Skip to main content
14,936,036 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi,

I have a dropdown list where i need to select any one from 1-4.
if i select 1 i want to read the first id(i.e parent id="1") inner nodes and store it to some variable.
If i select 2 the second id(i.e parent id="2") details should get stored.
so the xml file should be read on the value given for "id".

the xml file looks something like this
XML
<root>
  <greatgrandparent>
    <grandparent>
      <parent id="1">
        <child somevalue="3"></child>
      </parent>
      <parent id="2">
        <child somevalue="4"></child>
        <child somevalue="5"></child>
      </parent>
    </grandparent>
  </greatgrandparent>
</root>



can anyone help me out???
Thanks in advance.
Posted
Comments
Manas Bhardwaj 14-May-12 6:00am
   
So, whats the problem? Any effort?
Sandeep Mewara 14-May-12 6:58am
   
And where are you stuck?
qwerty 2 14-May-12 8:44am
   
I need to know how to get values based on field of the node..

1 solution

Here is the sample code:

C#
XmlNodeList nodes = XMLRead.SelectNodes(@"grandparent"); 
foreach (XmlNode node in nodes)            
{                 
     string event1 = node.InnerText;
     listBoxOuter.Items.Add(event1);

     foreach (XmlNode n in node)                 
     {                     
             string event2 = n.FirstChild.InnerText; 
             listBoxOuter.Items.Add(event2);

             XmlNodeList nodes2 = node.ChildNodes;

             for (int i = 0, ii = nodes2.Count; i < ii; i++)
             {
                    XmlNode n = nodes2.Item(i);
                    string event2 = n.InnerText;
                    listBoxInner.Items.Add(event2);
             }

      }                                                              
 }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900