views:

161

answers:

2

In Microsoft SQL Server 2005, there is the option to store within the database under "Database -> Type -> XML Schema Collection" a XML schema to validate against if you are viewing the database within SQL management studio.

What I need to do is store the schema under the specified path above, and then within code pull that schema out to use to validate other xml data. Is there a way to query this schema so that I can get the xsd text and then use it within a .net application to validate other xml? I just need the information to pull or query the xsd test out of a database.

+1  A: 

I don't know about pulling it back out, but you are mistaken about the purpose. The purpose isn't for SSMS. It's for validating XML stored in an XML column in the database, and for creating XML indexes, and for support of XQuery.

That said, I'm sure you could retrieve the schema using SMO, and there's probably a query over the system tables that would return it.

John Saunders
We are currently using the xml schema to validate xml within the database, but we also have a need to validate xml outside the database. We wanted one location to store the xsd, and sql server seemed like a valid solution for both. This way we wouldn't need to store the xsd within the database and also outside of it.
Aaron
+1  A: 

After doing some additional research, I found that you are able to query the xsd from the database using the xml_schema_namespace call from within sql server.

SELECT xml_schema_namespace(N'',N'OurXmlSchemaNameOnDatabase')

This will query the xsd and return it. Additional information can be found here.

Aaron