Link to home
Start Free TrialLog in
Avatar of Collindsouza
CollindsouzaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

read inner text based on a Attribute of xml node

how can I read inner text based on a Attribute of xml node?

I have the following xml file
<?xml version="1.0" encoding="utf-8" ?>
<Columns>
  <field enabled="true">Appl</field>
  <field enabled="true">Loc</field>
  <field enabled="true">RicExtn</field>
</Columns>

I am trying to open this xml file in C# and loop through each of the <field> element and if the attribute enabled="true"  then i want to extract the inntertext

i can get as far as the attibute is concerned however i'm unable to extract the inner text...

here is my code

            const string strFilename = "GroupBySelection.xml";
            XmlTextReader textReader = new XmlTextReader(strFilename);
            while (textReader.Read())
            {
                 if((textReader.NodeType == XmlNodeType.Element) && (textReader.Name == "field") )
                    if (textReader.GetAttribute("enabled") == "true")
                    {
                        //get the value of the inner text here
                    }
                       
            }

please help
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Collindsouza

ASKER

hi,

I had a look at the link and it doesnt really help me in my problem

all it does is looking trhrought the xml document using xmlReader and displaying the content...

how will it resolve my problem?
I found the solution to my problem....

here it is...

            XmlTextReader textReader = new XmlTextReader(strFilename);
            while (textReader.Read())
            {
                if ((textReader.GetAttribute("enabled") == "true") && (textReader.Name == "field"))
                {
                    ClientSelectionList.Add(textReader.ReadString());
                }
            }
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial