How to compare schemas and update data


is there way can compare 2 schema's , apply changes in xml data.

for example: 

 

i have table untyped xml column

·         table dbo.contacts(           

            contact_id                 int                     not null         primary key,

            schema_name          varchar(100)        null,

            attributes_xml            xml                    null   

)

i have multiple schemas in sys.xml_schema_collections.

one of them contactsschema

<xs:schema id="contactsschema"

    targetnamespace="http://tempuri.org/contactsschema.xsd"

    elementformdefault="qualified"

    xmlns="http://tempuri.org/contactsschema.xsd"

    xmlns:mstns="http://tempuri.org/contactsschema.xsd"

    xmlns:xs="http://www.w3.org/2001/xmlschema">

  <xs:complextype name="contact">

    <xs:sequence>

      <xs:element name="fname" type="xs:string" />

<xs:element name="lname" type="xs:string" />

      <xs:element name="age" type="xs:int"   />  

    </xs:sequence>

  </xs:complextype>

  <xs:element name="contacts">

    <xs:complextype >

      <xs:sequence minoccurs="0" maxoccurs="unbounded">

        <xs:element name="contact" type="contact" />

      </xs:sequence>

    </xs:complextype>

  </xs:element>

</xs:schema>

records added dbo. contacts table schemaname = ‘contactsschema’ , the related xml data  (while adding records validate xml dynamically: please see post: ( http://social.msdn.microsoft.com/forums/en-us/sqlxml/thread/1b122a53-7c96-447d-886e-55ac5ea4da53 ).

now schema changed.

 

contactsschema (after change):

 

<xs:schema id="contactsschema"

    targetnamespace="http://tempuri.org/contactsschema.xsd"

    elementformdefault="qualified"

    xmlns="http://tempuri.org/contactsschema.xsd"

    xmlns:mstns="http://tempuri.org/contactsschema.xsd"

    xmlns:xs="http://www.w3.org/2001/xmlschema">

  <xs:complextype name="contact">

    <xs:sequence>

      <xs:element name="firstname" type="xs:string" />

<xs:element name="lastname" type="xs:string" />

      <xs:element name="age" type="xs:int"   />

      <xs:element name="ssn" type="xs:string"   />

    </xs:sequence>

  </xs:complextype>

  <xs:element name="contacts">

    <xs:complextype >

      <xs:sequence minoccurs="0" maxoccurs="unbounded">

        <xs:element name="contact" type="contact" />

      </xs:sequence>

    </xs:complextype>

  </xs:element>

</xs:schema>

i drop , create contactsschema in xml schema collections.

how update xml data in contacts table schema: contactsschema.

is there better way compare old , new schema  , update xml data.


thank , appreciate help.

i dont think there easy way this. comparing schema not easy task in tsql. further, updating xml data based on schema makes complecated task. while doable bunch of complex tsql code, suggest explore possibilities of getting done may in .net. 

even in .net, comparing schema , re-formatting xml document might not easy. if can build xslt style sheet transform old data new structure, might easier. 



http://jacobsebastian.blogspot.com/


SQL Server  >  SQL Server XML



Comments

Popular posts from this blog

Reindexing

Users List

List of charts