December 18, 2013 at 5:36 am
I have a requirement where i want XML tags to be case insensitive in my xml queries.
For example:
DECLARE @myTable TABLE ( yourXML XML )
INSERT INTO @myTable SELECT '<z><a><b>1</b><c>2</c></a></z>'
INSERT INTO @myTable SELECT '<Z><A><b>1</b><c>2</c></A></Z>'
SELECT * FROM @myTable WHERE ( [yourXML].exist('for $x in /z/a where ( ($x/b[1]) = 1 ) return $x')>0 )
Returns output as
yourXML
<z><a><b>1</b><c>2</c></a></z>
But i want the output to display without considering case of the XML tag. So my desired output should be
yourXML
<z><a><b>1</b><c>2</c></a></z>
<Z><A><b>1</b><c>2</c></A></Z>
How it can be done?
December 18, 2013 at 8:04 am
Try this...
SELECT * FROM @myTable
WHERE
(CONVERT(XML,LOWER(CONVERT(VARCHAR(MAX),[yourXML]))).exist('for $x in /z/a where ( ($x/b[1]) = 1 ) return $x')>0 )
December 19, 2013 at 10:29 am
Sowbhari's solution is likely the most straightforward, but does have the (perhaps) nasty side-effect of forcing everything to lower case (i.e. data AND element names). If you absolutely must only do that to element names, you'd have to adjust your FLWOR query.
Something to the effect of
for $x in /* where lower-case(node-name($x))="r"
for $y in $x/* where lower-case(node-name($y))="a" and ( ($y/b[1]) = 1 )
return $x
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply