sql server - T-SQL Xquery Exist Method return nothing -


i have following xquery piece, i'm trying test outside of t-sql script:

    declare @x xml      select @x = n'<?xml version="1.0" encoding="utf-16"?>     <root xmlns="http://www.w3.org">         <header>             <record>                 <a99>                     <a99_01_0>                         <a99_01>test</a99_01>                         <a99_02>test</a99_02>                         <a99_03>test</a99_03>                     </a99_01_0>                 </a99>             </record>         </header>     </root>     ';   select @x.exist('//header/record/a99/a99_01_0/a99_01') 

i want check if there value between a99_01 tags, there is. according exist(), output keeps coming 0, indicating doesn't exist.

is there i'm missing? i've double checked make sure syntax exist() correct. appreciated!

yes - you're missing xml namespace defined in xml document!

select @x = n'<?xml version="1.0" encoding="utf-16"?>               <root xmlns="http://www.w3.org">                     ************************* 

you need change select to:

with xmlnamespaces(default 'http://www.w3.org')   select        @x.exist('//header/record/a99/a99_01_0/a99_01') 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -