469,306 Members | 2,485 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

text/string finder

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
Nov 12 '05 #1
2 9407

"C# newbie" <rs****@otxresearch.com> wrote in message
news:O7***************@TK2MSFTNGP09.phx.gbl...
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
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

or ....
any idea?

thanks in advance
c# newbiew

Nov 12 '05 #2
Yes thanks

"Dimitre Novatchev [MVP XML]" <dn********@yahoo.com> wrote in message
news:c1*************@ID-152440.news.uni-berlin.de...

"C# newbie" <rs****@otxresearch.com> wrote in message
news:O7***************@TK2MSFTNGP09.phx.gbl...
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
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

or ....
any idea?

thanks in advance
c# newbiew


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by johkar | last post: by
2 posts views Thread by charlie_M | last post: by
2 posts views Thread by UJ | last post: by
6 posts views Thread by larry mckay | last post: by
25 posts views Thread by electrixnow | last post: by
4 posts views Thread by Ahmed, Shakir | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.