AliRezaGoogle <as*******@yahoo.comwrote:
<snip>
No. I can not use what you mentioned. I use .Net Framework 2 with
VS2005
Okay, so you want XPath, probably. Here's a short but complete program
to demonstrate:
using System;
using System.Xml;
public class Test
{
const string SampleXml = @"
<inventory>
<books>
<book Name = 'CS'>First content</book>
<book Name = 'NLP of MT'>Second content</book>
<book Name = 'MT'>Third content</book>
</books>
</inventory>";
static void Main()
{
XmlDocument doc = new XmlDocument();
// You'd normally load from a file here, or
// something like that
doc.LoadXml(SampleXml);
XmlNode node = doc.SelectSingleNode
("/inventory/books/book[@Name='NLP of MT']");
Console.WriteLine("Found: {0}", node.InnerText);
}
}
Note that if you receive the name dynamically and it could be arbitrary
text, you end up with a trickier problem due to quoting etc. At that
point it may be better to programmatically look through all the book
elements. (There may be a way of effectively parameterising XPath
expressions, but I don't know it...)
--
Jon Skeet - <sk***@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com