Read value from a complex XML structure using SQL Server -


i trying read value in sql server query out of xml structure column of datatype ntext.

this xml structure want extract value read!!!:

<printerprocessdef xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns="http://dev.docuware.com/settings/workflow/processdef" id="3e62848d-040e-4f4c-a893-ed85a7b2878a" type="printerprocess" configid="c43792ed-1934-454b-a40f-5f4dfec933b0" enabled="true" pcid="2837f136-028d-47ed-abdc-4103bedce1d2" timestamp="2016-08-08t09:44:38.532415">   <configs>     <config xmlns:q1="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q1:printerprocessconfig" id="c43792ed-1934-454b-a40f-5f4dfec933b0" />     <config xmlns:q2="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q2:recognizeactconfig" id="b89a6fc2-5573-4034-978a-752c6c0de4cf">       <q2:header defaultrecognitiontechnology="ocr" defaultocrsettingsguid="00000000-0000-0000-0000-000000000000">       </q2:header>       <q2:body>         <q2:anchordefs />         <q2:zonedefs />         <q2:tabledefs />         <q2:facelayouts>         </q2:facelayouts>         <q2:facesamples>         </q2:facesamples>         <q2:sampledocument>           <metadata xmlns="http://dev.docuware.com/settings/common" filename="test - editor" mimetype="application/pdf" pagecount="1" sourceappname="c:\windows\system32\notepad.exe" documenttitle="test - editor" pdfcreator="docuware printer" />           <data xmlns="http://dev.docuware.com/settings/common">!!!value read!!!</data>         </q2:sampledocument>       </q2:body>       <q2:allpagesrequired>false</q2:allpagesrequired>     </config>     <config xmlns:q3="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q3:recognizeactconfig" id="db5b195d-79e4-4804-bd38-f4fc7e8d5a8d">     </config>     <config xmlns:q4="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q4:addoverlayactconfig" id="023aab08-c6e3-4f08-9d26-0175d1564ef2">       <q4:overlays />     </config>     <config xmlns:q5="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q5:printactconfig" id="4a4ec06a-8652-4777-84d2-53cb862b3328">     </config>     <config xmlns:q6="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q6:signactconfig" id="8c030961-e68e-4c2f-83f1-cac20f51d4d6">     </config>     <config xmlns:q7="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q7:emailactconfig" id="5dbd144b-5c33-407a-b638-e062f9045fb4">     </config>     <config xmlns:q8="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q8:indexactconfig" id="f2a70e07-d76e-4e82-9313-7c665df4c311">     </config>     <config xmlns:q10="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q10:storeactconfig" id="ff8aec66-608e-4dde-a4b6-de65ada39bb0">     </config>     <config xmlns:q11="http://dev.docuware.com/settings/workflow/processconfig" xsi:type="q11:notifyuseractconfig" id="7ffb0437-6b8c-4f5f-8f40-434f4a6d609a" />   </configs>   <activities>   </activities> </printerprocessdef> 

and sql query used:

select      cast([table].[settings] xml)         .value('declare namespace q2="http://dev.docuware.com/settings/workflow/processconfig";         (/printerprocessdef/configs/config[@xsi:type="q2:recognizeactconfig"]/q2:body/q2:sampledocument/data/text())[1]',         'varchar(max)')      [db].[dbo].[table] 

all returned null , not hoped-for value read!!!.

what should query working?

i tried different versions without namespace declaration , others null.

all elements have namespaces defined. need declare , specify them according definitions

select cast([table].[settings] xml).value(    'declare namespace top="http://dev.docuware.com/settings/workflow/processdef";     declare namespace q2="http://dev.docuware.com/settings/workflow/processconfig";     declare namespace nd="http://dev.docuware.com/settings/common";     (/top:printerprocessdef/top:configs/top:config[@xsi:type="q2:recognizeactconfig"]/q2:body/q2:sampledocument/nd:data)[1]',           'varchar(max)') [db].[dbo].[table] 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -