all groups > dotnet xml > february 2004 >
You're in the

dotnet xml

group:

text/string finder



text/string finder C# newbie
2/25/2004 12:20:48 PM
dotnet xml: Hi,

I'm new to xml and sometimes gives me a hardtime. is there any xpah query
that returns a particular string I'm looking for?

I used: //*contains(text()="foo") the "foo" could be in any part of xml
file. it could be text or attribute or ....
any idea?

thanks in advance
c# newbiew

Re: text/string finder C# newbie
2/25/2004 3:27:41 PM
Yes thanks

[quoted text, click to view]

Re: text/string finder Dimitre Novatchev [MVP XML]
2/25/2004 10:14:51 PM

[quoted text, click to view]

This is not a syntactically correct XPath expression.

Probably you meant:

//*[contains(text(), 'foo')]


This will select all *element* nodes that have at least one *text node*
child that contains the string 'foo'

No attribute nodes will be selected.

If you need an XPath expression that will also select all attribute nodes
containing the string 'foo', one such XPath expression is:

(//* | //@*)[contains(., 'foo')]

If you want to include other types of nodes in the search, too (e.g.
comments and processing instructions), then one way to select all such
nodes, containing the string 'foo' is to evaluate the following XPath
expression:

(//node() | //@*)[contains(., 'foo')]


If you need to extend your search over namespace nodes, too, use this XPath
expression:

(//node() | //@* | //namespace::*)[contains(., 'foo')]


Hope this helped.


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html




[quoted text, click to view]

AddThis Social Bookmark Button