• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1348
  • Last Modified:

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
0
Collindsouza
Asked:
Collindsouza
  • 2
1 Solution
 
CollindsouzaAuthor Commented:
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?
0
 
CollindsouzaAuthor Commented:
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());
                }
            }
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now