Getting child XmlNodeList and sub-child XmlNodeList from XmlNode

Hi

I am working in ASP.net3.5 using C#

I can getting XmlNodeList from my code and Its working great

XmlNodeList Alist = Ftemp[new string[] { "TripDetails", "TripCaption" }];
           
for (int i1 = 0; i1 < Alist.Count; i1++)
{
      System.Xml.XmlNode FNode = Alist[i1];
}

If I loop through each Node. I get Label Node

The sample of Node is

<Label name="Duration" isRequired="True" orderno="0" helpingtext="Number of days!" questionID="11" questionFormat="2">
      <Control type="Text Field (Single Line)" questionFormat="2" maxCount="1" displayCount="1" canAddMoreControls="False">
        <FieldValue id="11" visible="True">17</FieldValue>
        <FieldValue id="12" visible="True">18</FieldValue>
        <FieldValue id="18" visible="True">200</FieldValue>
      </Control>
    </Label>
   
 
How can I get attribute and value of another node called 'FieldValue'

I reached Label node, then how do I reach there childlist and sub childlist

Please guide
tia_kamakshiAsked:
Who is Participating?
 
paololabeCommented:
try this
xLabelNode.SelectNodes("Control/FieldValue"); // return node list
//loop on list and get attributes
//f.e. xNode.Attributes["id"]

Open in new window

0
 
anarki_jimbelCommented:
Try something like in my snippet (tested):
                    string filename = "XMLFile1.xml";
                    XmlDocument doc = new XmlDocument();

                    if (File.Exists(filename))
                    {
                        doc.Load(filename);
                        XmlElement docEle = doc.DocumentElement;
                        doc.AppendChild(docEle);
                        XmlNodeList fieldValueNodes = docEle.GetElementsByTagName("FieldValue");
                        foreach (XmlNode node in fieldValueNodes)
                        {
                            XmlElement fieldValueEle = (XmlElement)node;
                            MessageBox.Show("ID = " + fieldValueEle.GetAttribute("id") + Environment.NewLine +
                                "Visible = " + fieldValueEle.GetAttribute("visible") + Environment.NewLine +
                                "Value = " + fieldValueEle.InnerText);
                        }
                    }
                    else
                    {
                        MessageBox.Show("file does not exists");
                    }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.