471,089 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

simple problem with xpath function contains!

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
Nov 7 '08 #1
2 6183
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.
--
Stanimir Stoyanov
http://stoyanoff.info

"giddy" <gi***@discussions.microsoft.comwrote in message
news:FC**********************************@microsof t.com...
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
Nov 7 '08 #2

Thank you so much Stanimir, works great! You saved me hours of frustration!
Nov 8 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Ot | last post: by
2 posts views Thread by sprungli | last post: by
2 posts views Thread by Jesper | last post: by
6 posts views Thread by Armel Asselin | last post: by
5 posts views Thread by jorgedelgadolopez | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.