Collindsouza
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</fi eld>
</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
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</fi
</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("
{
//get the value of the inner text here
}
}
please help
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 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?
ASKER
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(te xtReader.R eadString( ));
}
}
here it is...
XmlTextReader textReader = new XmlTextReader(strFilename)
while (textReader.Read())
{
if ((textReader.GetAttribute(
{
ClientSelectionList.Add(te
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.c-sharpcorner.com/uploadfile/mahesh/readwritexmltutmellli2111282005041517am/readwritexmltutmellli21.aspx