simple problem with xpath function contains!

G

giddy

hi,

!!Please help! I've been at this for a few hours now! I'm probably doing
something silly.

heres my xml document:

<Log>
<entry user="Gideon" date="11/6/2008" time="10:14 AM" action="Searched" />
<entry user="Jennie" date="11/6/2008" time="10:14 AM" action="Finished her
papers" />
<entry user="Gideon" date="11/7/2008" time="10:14 AM" action="tested" />
<entry user="Apphia" date="11/7/2008" time="10:14 AM" action="signed out" />
</Log>

And none of these queries with functions return anything!!

XmlNodeList lst = xel.SelectNodes("//entry[contains(.,'Searched')]");
XmlNodeList lst = xel.SelectNodes("//entry[contains(action,'Searched')]");
XmlNodeList lst = xel.SelectNodes("//entry[contains(user,'Gid')]");

What am i doing wrong!?

The whole code looks like:
XmlDocument xel = new XmlDocument();
xel.Load(filename);
XmlNodeList lst = xel.SelectNodes("//entry[contains(user,'Gid')]");


Thanks so much

Gideon
 
S

Stanimir Stoyanov

Hi Gideon,

Your usage of contains(., 'Searched') was instructing XPath to find 'entry'
nodes whose _inner text_ contains Searched, while you want to search the
'action' attribute. Use "attribute::action" instead of "." in the first
couple of expressions, and "attribute::user" in the last one.
 

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