sql server - sp_xml_preparedocument does not recognize validated xml variable -


can trying shred xml document data table in sql server. using xml schema collection validate xml document. below copy of xml schema

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"   targetnamespace="http://www.healthcenter.com" xmlns="http://www.healthcenter.com"  xmlns:sql="urn:schemas-microsoft-com:mapping-schema" elementformdefault="qualified"   version="2.0.1.1">    <xs:element name="healthcenter">     <xs:complextype>       <xs:sequence>        <xs:element name="patients" type="patientdetails"/>     <xs:element name="doctors"  type="doctorsdetails"/>     <xs:element name="ailment"  type="ailementdetails"/>    </xs:sequence>  </xs:complextype> </xs:element> <xs:complextype name="patientdetails"> <xs:sequence>   <xs:element name="patientid" type="xs:integer"/>   <xs:element name="firstname" type="xs:string"/>   <xs:element name="lastname" type="xs:string"/>   <xs:element name="age" type="xs:string"/>   <xs:element name="ailementid" type="xs:integer"/>   <xs:element name="doctorid" type="xs:integer"/> </xs:sequence> </xs:complextype> <xs:complextype name="doctorsdetails"> <xs:sequence>   <xs:element name="doctorid" type="xs:integer"/>   <xs:element name="doctorname" type="xs:string"/>   <xs:element name="doctortype" type="doctorcategory"/> </xs:sequence> </xs:complextype>   <xs:complextype name ="ailementdetails"> <xs:sequence>   <xs:element name ="ailementid" type="xs:integer"/>   <xs:element name ="ailementname" type="xs:string"/>   <xs:element name ="ailementcode" type="ailmentcodetypes"/>    </xs:sequence> </xs:complextype>       <xs:simpletype name="doctorcategory">    <xs:restriction base="xs:string">    <xs:enumeration value="dentist"/>    <xs:enumeration value="physiotherapist"/>    <xs:enumeration value="gynocologist"/>    <xs:enumeration value="generalprctitioner"/>  </xs:restriction> </xs:simpletype>     <xs:simpletype name="ailmentcodetypes">    <xs:restriction base="xs:string">   <xs:enumeration value="sde"/>   <xs:enumeration value="sie"/>   <xs:enumeration value="sue"/>   <xs:enumeration value="nre"/>  </xs:restriction> </xs:simpletype> </xs:schema>'   --xml validation  declare @xmldata xml(dbo.doctorpatients) declare @idoc int set @xmldata = '<healthcenter xmlns="http://www.healthcenter.com"> <patients>     <patientid>1</patientid>     <firstname>micheal</firstname>     <lastname>huie</lastname>     <age>28</age>     <ailementid>1</ailementid>     <doctorid>1</doctorid> </patients> <doctors>     <doctorid>1</doctorid>     <doctorname>sheldon huie</doctorname>     <doctortype>dentist</doctortype> </doctors> <ailment>     <ailementid>1</ailementid>     <ailementname>dementia</ailementname>     <ailementcode>sde</ailementcode> </ailment>   </healthcenter> 

here how go shredding data table using sp_xml_preparedocument , openxml

    exec sp_xml_preparedocument @idoc output,@xmldata     select *          openxml(@idoc,'/healthcenter/patients',2)     with(patientid int,          firstname varchar(50),          lastname varchar(50),          age varchar(3),          ailementid int,          doctorid int          )       exec sp_xml_removedocument @idoc  

the above produces error message in sql server

msg 6628, level 16, state 1, procedure sp_xml_preparedocument, line 1
sp_xml_preparedocument can process untyped xml. cast input value xml or string type.
msg 8179, level 16, state 5, line 26
not find prepared statement handle 0.
msg 6607, level 16, state 3, procedure sp_xml_removedocument, line 1
sp_xml_removedocument: value supplied parameter number 1 invalid.

i think have done right if can spot why such error message greatful. note have not yet attempted insert data table, wanted display data first.

forgive formatting had rearrange in order text in code blocks

i try use native xquery support in sql server 2005 , newer, rather clunky , memory-intensive openxml code.

try - work xml schema collection?

;with xmlnamespaces(default 'http://www.healthcenter.com') select     patientid = patients.value('(patientid)[1]', 'int') ,     patientfirstname = patients.value('(firstname)[1]', 'varchar(50)') ,     patientlastname = patients.value('(lastname)[1]', 'varchar(50)') ,     patientage = patients.value('(age)[1]', 'int') ,     patientailmentid = patients.value('(ailementid)[1]', 'int') ,     patientdoctorid = patients.value('(doctorid)[1]', 'int')      @xmldata.nodes('/healthcenter/patients') xtbl(patients) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -