364,085 Members | 5253 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

text/string finder

C# newbie
P: n/a
C# newbie
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
Share this Question
Share on Google+
2 Replies


Dimitre Novatchev  [MVP XML]
P: n/a
Dimitre Novatchev [MVP XML]

"C# newbie" <rsavra@otxresearch.com> wrote in message
news:O7Lrky9%23DHA.220@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]

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



[color=blue]
> or ....
> any idea?
>
> thanks in advance
> c# newbiew
>
>[/color]


Nov 12 '05 #2

C# newbie
P: n/a
C# newbie
Yes thanks

"Dimitre Novatchev [MVP XML]" <dnovatchev@yahoo.com> wrote in message
news:c1j2i3$1eg75j$1@ID-152440.news.uni-berlin.de...[color=blue]
>
> "C# newbie" <rsavra@otxresearch.com> wrote in message
> news:O7Lrky9%23DHA.220@TK2MSFTNGP09.phx.gbl...[color=green]
> > Hi,
> >
> > I'm new to xml and sometimes gives me a hardtime. is there any xpah[/color][/color]
query[color=blue][color=green]
> > that returns a particular string I'm looking for?
> >
> > I used: //*contains(text()="foo") the "foo" could be in any part of[/color][/color]
xml[color=blue][color=green]
> > file. it could be text or attribute[/color]
>
> 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[/color]
XPath[color=blue]
> 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
>
>
>
>[color=green]
> > or ....
> > any idea?
> >
> > thanks in advance
> > c# newbiew
> >
> >[/color]
>
>[/color]


Nov 12 '05 #3

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework