473,704 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="Searche d" />
<entry user="Jennie" date="11/6/2008" time="10:14 AM" action="Finishe d 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(.,'Sea rched')]");
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(filena me);
XmlNodeList lst = xel.SelectNodes ("//entry[contains(user,' Gid')]");
Thanks so much

Gideon
Nov 7 '08 #1
2 6297
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::act ion" instead of "." in the first
couple of expressions, and "attribute::use r" in the last one.
--
Stanimir Stoyanov
http://stoyanoff.info

"giddy" <gi***@discussi ons.microsoft.c omwrote in message
news:FC******** *************** ***********@mic rosoft.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="Searche d"
/>
<entry user="Jennie" date="11/6/2008" time="10:14 AM" action="Finishe d
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(.,'Sea rched')]");
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(filena me);
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1927
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
1
2975
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the following statement fails to find a node (even though one exists in the XML) if the value of the LDAPServerURL attribute is \\LocalServer but works if the value is "LocalServer".
7
5490
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned that an xpath expression can be bounded by either single or double quotation marks. But sometimes I want to search for a title containing both a single and double quote. Any way to do this?
2
20757
by: sprungli | last post by:
My goal is to select some XPath nodes based on whether their values (text) contain a string passed as argument. To achieve this I use the contains() function of XPath in an XpathExpression. For example, given the following fragment... <code> <Exprs> <Expr>red fox</Expr> <Expr>jump over</Expr>
2
4849
by: tschulken | last post by:
I am trying to get certain nodes within an xml doc that contain certain text (similar to a SQL LIKE). In doing so I am using the XPATH Contains function and have not been successful. When I run I get the following error: System.Xml.XPath.XPathException: XsltContext is needed for this query because of an unknown function. I can successfully get simple xpath queries to work, just none using the Contains function. Any help would be...
2
1859
by: Jesper | last post by:
Hi, Sorry if this is not hte right group, but I couln't find a XPath group. In a XML document I have an attribute that conatains a text. I would like the node to be selected if the attibute contains a specified substring. Is it possibe to use the XPath function 'contains()' to filter out a substring in an attribure. I can only find XSL examples. If I have :
2
1891
by: smachin1000 | last post by:
Hi All, In the sample schema & document below, I'd like the attribute "name" to be unique for all function elements under function_list. The tools I'm using (XML Spy and xmllint) all validate the sample document and do not pick up that the name is not unique. Any clues as to what could be going wrong? Thanks.
6
6826
by: Armel Asselin | last post by:
Hello, I'm searching for a simple command line tool to manipulate XML files. The idea would be commands such as that: xmanip-tool set /document/xpath/@name="value" remove //wrong-nodes add /document/node=\<hello\ < in.xml out.xml so, it would simple add/remove/change commands (either as arguments or input script file), a bit of xpath and the usual Unix parameters (-o output,-f
5
50578
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'), and so on. This is the thought: //person
0
8767
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9135
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7893
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4439
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2485
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.