?
Solved

Getting child XmlNodeList and sub-child XmlNodeList from XmlNode

Posted on 2009-12-20
2
Medium Priority
?
560 Views
Last Modified: 2012-05-08
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
0
Comment
Question by:tia_kamakshi
2 Comments
 
LVL 8

Accepted Solution

by:
paololabe earned 2000 total points
ID: 26091772
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
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 26092301
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

755 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