0

Trying to get all the words in text nodes which start with a capital letter, trying

SelectNodes("//*[contains(text(), [A-Z])]"); but wont compile, I'm new to regex and i really can't find anything, looked everywhere.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
AreyouZURE
  • 43
  • 8

1 Answers1

1

Try this:

SelectNodes("//*[matches(text(), '^[A-Z]')]");

However, you may need to follow these steps before it will work.

Community
  • 1
  • 1
C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • thanks, it is says "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function." now though, what have i failed this time? – AreyouZURE Aug 23 '13 at 02:48
  • A quick Google turned this up: http://stackoverflow.com/q/13511527/13. It sounds like your XML has some namespaces that has to be added to the namespace manager. – C. K. Young Aug 23 '13 at 02:50
  • I'm getting the error "XsltContext is needed for this query because of an unknown function." the common answer is people using.net and not having xpath 2 it seems, im using visual studio 11, would this have xpath 2? is this the issue? – AreyouZURE Aug 23 '13 at 03:00
  • Oh dear, that's because .NET doesn't actually support XPath 2.0 out of the box: http://stackoverflow.com/q/6447476/13 (see the top answer for a workaround). – C. K. Young Aug 23 '13 at 03:02
  • .NET is the name of the platform that C# programs run on. :-D – C. K. Young Aug 23 '13 at 03:12
  • weird that i was asked to do this for a job interview then (they know ive never programmed in c# before) – AreyouZURE Aug 23 '13 at 03:23
  • I guess they were trying to tell how "never" you've done C#. :-P – C. K. Young Aug 23 '13 at 03:23
  • The solution given using matches() is correct for XPath 2.0. However, .NET does not support XPath 2.0 "out of the box" - you need to install something like Saxon or XmlPrime. – Michael Kay Aug 23 '13 at 08:54