Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing XML data

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
I have some XML (see snippet below) and I have got so far with it, but I don't know how to get at the text within the <Value> tags :

<ResponseGroup refID="AnswerGroup184">
<ResponseText refID="Textbox25">
<Value>Mike</Value>
</ResponseText>
<ResponseText refID="Textbox26">
<Value>P</Value>
</ResponseText>
<ResponseText refID="Textbox27">
<Value>Blue Orc</Value>
</ResponseText>
<ResponseText refID="Textbox28">
<Value>01234</Value>
</ResponseText>
<ResponseText refID="Textbox29">
<Value>m@p.com</Value>
</ResponseText>
<ResponseText refID="Textbox30">
<Value>1234</Value>
</ResponseText>
<ResponseText refID="Textbox31">
<Value />
</ResponseText>
</ResponseGroup>

Here is my code :

foreach (XmlElement rGroup in
doc.SelectNodes
("/df:ScriptedFaqSession/df:Data/df:Section/df:ResponseGroup", mgr))
{
//contact details
if (rGroup.GetAttribute("refID") == "AnswerGroup184")
{
foreach (XmlElement rOption in rGroup.SelectNodes
("df:ResponseText", mgr))
{
if (rOption.GetAttribute("refID").ToString()
== "Textbox25")
{

}
}
}
}

What is the correct syntax to get the text within the <Value> tags?
 
using xpath queries it's something like
Code:
var value = doc.SelectNode(@"\\ResponseGroup[refID='AnswerGroup184']\ResponseText[refID='Textbox25']\Value").Value;
or
Code:
var value = doc.SelectNode(@"\\ResponseGroup[refID='AnswerGroup184']\ResponseText[refID='Textbox25']\Value").Text;
no ulgy if/thens or foreach loops

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top