Getting child XmlNodeList and sub-child XmlNodeList from XmlNode

Posted on 2009-12-20
Last Modified: 2012-05-08

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>
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
Question by:tia_kamakshi
    LVL 8

    Accepted Solution

    try this
    xLabelNode.SelectNodes("Control/FieldValue"); // return node list
    //loop on list and get attributes
    //f.e. xNode.Attributes["id"]

    Open in new window

    LVL 29

    Expert Comment

    Try something like in my snippet (tested):
                        string filename = "XMLFile1.xml";
                        XmlDocument doc = new XmlDocument();
                        if (File.Exists(filename))
                            XmlElement docEle = doc.DocumentElement;
                            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);
                            MessageBox.Show("file does not exists");

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now