Hi Patrick,
You weren't using the correct syntax to locate using an attribute value. You
need to use @id= for that.
Here's some code that should get you going:
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(FetchFieldFromXml("09"));
}
private string FetchFieldFromXml(string strId)
{
XmlNode fetchnode;
XmlDocument mydoc = new XmlDocument();
mydoc.Load(Server.MapPath(@"frm.xml"));
fetchnode =
mydoc.SelectSingleNode(@"/fields/formmonthnames/monthnames[@id='" + strId +
"']");
return fetchnode.InnerText;
}
<?xml version="1.0" encoding="iso-8859-1" ?>
<fields>
<formmonthnames>
<monthnames id="01">January</monthnames>
<monthnames id="02">February</monthnames>
<monthnames id="03">March</monthnames>
<monthnames id="04">April</monthnames>
<monthnames id="05">May</monthnames>
<monthnames id="06">June</monthnames>
<monthnames id="07">July</monthnames>
<monthnames id="08">August</monthnames>
<monthnames id="09">September</monthnames>
<monthnames id="10">October</monthnames>
<monthnames id="11">November</monthnames>
<monthnames id="12">December</monthnames>
</formmonthnames>
</fields>
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
"Patrick F" <Pa******@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
how do i select a single node value from the list?
ive tried with this, but it dosent work =/
private string FetchFieldFromXml(string strId)
{
string strText = "";
XmlNode fetchnode;
XmlDocument mydoc = new XmlDocument();
try
{
mydoc.Load(strXmlFieldPath);
fetchnode =
mydoc.SelectSingleNode("//fields//formmonthnames//monthnames[id=" + strId
+
"]");
strText = fetchnode.InnerText;
}
catch (Exception e)
{
}
return strText;
}
xmlfile looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<fields>
<formmonthnames>
<monthnames id="01">January</monthnames>
<monthnames id="02">February</monthnames>
<monthnames id="03">March</monthnames>
<monthnames id="04">April</monthnames>
<monthnames id="05">May</monthnames>
<monthnames id="06">June</monthnames>
<monthnames id="07">July</monthnames>
<monthnames id="08">August</monthnames>
<monthnames id="09">September</monthnames>
<monthnames id="10">October</monthnames>
<monthnames id="11">November</monthnames>
<monthnames id="12">December</monthnames>
</formmonthnames>
</field>