XPath querry...

S

Son Ha

Hi newsgroup!
My English is not so good please try to understand my mind 8-]

My XML file as below:
[UserAuthentication.xml]
<?xml version="1.0" encoding="UTF-8"?>
<Users>
<User name="Administrator" pwd="password"/>
<User name="Guest" pwd="guess"/>
</Users>

Here's my XPath querry:
public static void RunXPath()
{
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"F:\Projects\CSharp\Freeware\DocMan\bin\Debug\UserAuthentication.xml");
XmlNodeList nodes = xmlDoc.SelectNodes(@"/Users/User[name='Administrator']");
foreach(XmlNode node in nodes)
{
Debug.WriteLine(node.OuterXml);
}
}

When i ran this code, nothing display in debug window :(

Thanks for your help,
MK
 
M

Mike Ryan

Hello,

When I prefixed your name attribute with '@' your expression worked for
me, as follows:

xmlDoc.SelectNodes(@"/Users/User[@name='Administrator']");

Does that work for you? [You can always check the node count first to
make sure you have a match.]

- Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top