3

I need to make script of XML schema collections in my Database and then insert each xml inside a table field as string.

I need to do this to compare current schema collections with the new schema collections after it is regenerated.

I have no idea where to start!

Solomon Rutzky
70.1k8 gold badges160 silver badges306 bronze badges
asked Jun 15, 2016 at 14:14
0

1 Answer 1

3

If I understand the Question correctly, you need to use the XML_SCHEMA_NAMESPACE built-in function to extract the Schema Collection, and you can find the list of those in the sys.xml_schema_collections system catalog view. You can use something along the lines of:

SELECT CONVERT(NVARCHAR(MAX), XML_SCHEMA_NAMESPACE(sch.[name], xsc.[name])) AS [XSD]
FROM sys.xml_schema_collections xsc
INNER JOIN sys.schemas sch
 ON sch.[schema_id] = xsc.[schema_id]
WHERE xsc.[xml_collection_id] <> 1;

I put the WHERE xsc.[xml_collection_id] <> 1 filter in there to avoid getting the following error:

Msg 6314, Level 16, State 1, Line 1
Collection specified does not exist in metadata : 'sys'

answered Jun 15, 2016 at 15:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.