简体   繁体   English

SQL Server XML数据类型

[英]SQL Server XML data type

I have a table in SQL Server 2005 SP4; 我在SQL Server 2005 SP4中有一张表; in which one of the column will be of XML data type. 其中列之一将是XML数据类型。

The problem is my XML can be of three different formats. 问题是我的XML可以是三种不同的格式。 (ie XML is not same but can be up to three different format) I want to use typed XML so (即XML不相同,但最多可以使用三种不同格式)我想使用类型化XML,因此

Question a) can I create XML schema collection that has XML schema for three different xml 问题a)我可以创建具有针对三个不同xml的XML模式的XML模式集合吗

I see a table in adventureworks database, Production.ProductModel in which catalogdescription column has three different schemas applied to it. 我在Adventureworks数据库Production.ProductModel中看到一个表,其中catalogdescription列将三个不同的模式应用于该表。

b) XML will be generated from ASP.net webform; b)XML将从ASP.net Webform生成; should I construct XML in ASP.net or bring all form data in to SQL and construct XML there? 我应该在ASP.net中构造XML还是将所有表单数据导入SQL并在那里构造XML?

Thanks 谢谢

For your first question - yes, you can define an XML schema collection which can - as the name "collection" implies - contain multiple XML schemata: 对于第一个问题-是的,您可以定义一个XML模式集合,正如名称“ collection”所暗示的那样,该模式集合可以包含多个XML模式:

-- First create an XML schema collection.
CREATE XML SCHEMA COLLECTION MySchemaCollection 
  AS '<schema .......> ...... </schema>'

-- Modify the collection. 
ALTER XML SCHEMA COLLECTION MySchemaCollection 
  ADD '<schema ......>  ...... </schema>'

This way, you can define three separate schematas for your three types of XML data. 这样,您可以为三种类型的XML数据定义三个独立的模式。

See the MSDN documatation Managing XML Schema Collections in SQL Server for more details. 有关更多详细信息,请参见MSDN文档“ 在SQL Server中管理XML架构集合”

As for your second question: I would guess that it probably is easier to just create it in your ASP.NET app and store it after it's been generated - otherwise you would have to first store the data in some kind of relational form (tables) and then generate XML from those. 至于您的第二个问题:我想可能只是在ASP.NET应用程序中创建它并在生成后存储它会更容易-否则,您将不得不首先以某种关系形式(表)存储数据然后从中生成XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM