Groups | Blog | Home
all groups > dotnet xml > may 2004 >

dotnet xml : XPath contains() function



sprungli
5/21/2004 4:31:09 PM
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

Bjoern Hoehrmann
5/22/2004 12:45:22 AM
* sprungli wrote in microsoft.public.dotnet.xml:
[quoted text, click to view]

Pass e.g. '.' or 'text()' as the first argument to contains as that
sprungli
5/22/2004 4:50:31 PM
Thanks Bjoern, that helped.

---
[quoted text, click to view]

AddThis Social Bookmark Button