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:

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
      <parent id="1">
        <child somevalue="3"></child>
      <parent id="2">
        <child somevalue="4"></child>
        <child somevalue="5"></child>

can anyone help me out???
Thanks in advance.
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:

XmlNodeList nodes = XMLRead.SelectNodes(@"grandparent"); 
foreach (XmlNode node in nodes)            
     string event1 = node.InnerText;

     foreach (XmlNode n in node)                 
             string event2 = n.FirstChild.InnerText; 

             XmlNodeList nodes2 = node.ChildNodes;

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


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