read inner text based on a Attribute of xml node

Posted on 2008-11-07
Last Modified: 2012-05-05
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" ?>
  <field enabled="true">Appl</field>
  <field enabled="true">Loc</field>
  <field enabled="true">RicExtn</field>

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
Question by:Collindsouza
    LVL 13

    Expert Comment

    LVL 5

    Author Comment


    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?
    LVL 5

    Author Comment

    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"))
    LVL 1

    Accepted Solution

    PAQed with points refunded (500)

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    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!

    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…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 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

    13 Experts available now in Live!

    Get 1:1 Help Now