Re: Reading an XMLFile
- From: "Morten Wennevik [C# MVP]" <MortenWennevik@xxxxxxxxxxx>
- Date: Fri, 09 Feb 2007 10:11:37 +0100
Hi Jon,
I prefer XmlDocument and selecting nodes using XPath queries when reading xml, so below is an alternative solution.
Claimkey is not in your sample xml so I don't know where it would be.
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"c:\xml\isn_prod.XML-0139.xml");
XmlNodeList list = doc.SelectNodes("/comment_list/comment");
foreach (XmlNode node in list)
{
sb.AppendLine("Date: " + node["date"].InnerText);
sb.AppendLine("Author: " + node["author"].InnerText);
sb.AppendLine("Visible to: " + node["visible_to"].InnerText);
sb.AppendLine("Comment: " + node["comment"].InnerText);
}
If you just want a single comment node based on its item_no attribute, use
XmlNode node = doc.SelectSingleNode("/comment_list/comment[@item_no='2']");
--
Happy Coding!
Morten Wennevik [C# MVP]
.
- References:
- Reading an XMLFile
- From: Jon
- Reading an XMLFile
- Prev by Date: RE: how to specify private key to generate signature
- Next by Date: Re: Net.Mail attachments
- Previous by thread: Reading an XMLFile
- Next by thread: Re: Running Applications
- Index(es):
Relevant Pages
|