473,246 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XPath contains() function

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>
<Expr>box</Expr>
</Exprs>
</code>

.... I want to select the second <Expr> and test whether it contains the
string argument "jump":
(I am passing values to the contains() function dynamically, but here I
will use static values for clarity.)

<code>
xPthExpr = xPathNavig.Compile("/Exprs/Expr[contains(" + "jump over," +
"jump" + ")]" );
xPathNodeIter = xPathNavig.Select(xPthExpr);
</code>

Now, of course contains() returns true for all the nodes and all the nodes
get selected. Instead, I want a behaviour like this: select ONLY the node(s)
where the value CONTAINS (not is equal to) "jump", something like the LIKE
SQL clause.Can I do this w/ XPath at all? I need it instead XmlDocument for
sake of speed.

TIA
Nov 12 '05 #1
2 20706
* sprungli wrote in microsoft.public.dotnet.xml:
... I want to select the second <Expr> and test whether it contains the
string argument "jump": <code>
xPthExpr = xPathNavig.Compile("/Exprs/Expr[contains(" + "jump over," +
"jump" + ")]" );
xPathNodeIter = xPathNavig.Select(xPthExpr);
</code>


Pass e.g. '.' or 'text()' as the first argument to contains as that
would refer to the string value of the first text child of the element.
Nov 12 '05 #2
Thanks Bjoern, that helped.

---
"Bjoern Hoehrmann" <bj****@hoehrmann.de> wrote in message
news:40***************@news.bjoern.hoehrmann.de...
* sprungli wrote in microsoft.public.dotnet.xml:
... I want to select the second <Expr> and test whether it contains the
string argument "jump":

<code>
xPthExpr = xPathNavig.Compile("/Exprs/Expr[contains(" + "jump over," +
"jump" + ")]" );
xPathNodeIter = xPathNavig.Select(xPthExpr);
</code>


Pass e.g. '.' or 'text()' as the first argument to contains as that
would refer to the string value of the first text child of the element.

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the...
4
by: Vitali Gontsharuk | last post by:
Hallo! When using the XPATH document() function to load a new XML document, we are coming across problems, because XALAN seems to have problems with absolute paths. XALAN always assumes that the...
1
by: Damien Goutte-Gattat | last post by:
I am using the .NET framework v2.0.40607 with Visual C# Express and I would like to create some custom XPath functions to use directly in a XSLT stylesheet. I called...
2
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...
2
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...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
5
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'),...
2
by: =?Utf-8?B?Z2lkZHk=?= | last post by:
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"...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.