-1

How to match the case in xml node data. I need to search the xml node data and match the given string with xml node data. Matching is required on:

  • Match Case
  • Exact Match

Any help in this regard is warmly welcom.

Itz.Irshad
  • 1,014
  • 5
  • 23
  • 44

3 Answers3

1

The functions lower-case() and upper-case() are only available in XPath 2.0 and upper versions.

In XPath 1.0 for case-insensitive string comparison use:

translate($string1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')
=
 translate($string2, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')

where $string1 and $string2 are expressions specifying the strings to be compared.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

You may want to have a look at section 7.6.2 of the XPath spec:

http://www.w3.org/TR/xpath-functions/#func-matches

With the fn:matchesfunction you write a regular expression to match your desired target string.

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • I'm not supposed to match xml node data with some pattern here. But, node element data with user input value. I've a sub-child of book node. ` ASP.NET ` and user input a value in text box *asp.net*. Here, I need to match the case. My xpath expression which returs the title of book is: `"book[title='"+txtBookTitle.text+"']"` Can you shed some light how to achieve this ? – Itz.Irshad Jul 18 '12 at 06:11
  • The function fn:matches works on element data, so I would expect that something like `/book[fn:matches( title , '.*asp.net.*' )]` works for you (the `asp.net` is of course your query string). Come to think of it, `fn:contains` may also work, although I'm unsure of the case-sensitivity... – Anders R. Bystrup Jul 18 '12 at 08:00
0

Try lower-case or upper-case String functions. That's not quite the same as case-insensitive, but hopefully it will be close enough:

//YourNode[lower-case(@title)='anders rostgaard bystru']

see this post for other solutions.

Community
  • 1
  • 1
Ria
  • 10,237
  • 3
  • 33
  • 60