sql-server - sql服务器: Bind Xml schema to a column of a Table

标签 sql-server xml

首先,我对这些东西完全陌生,所以请不要强硬。 我正在创建一个 XML 架构:

USE SampleDatabase;
GO
CREATE XML SCHEMA COLLECTION ManuInstructionsSchemaCollection AS
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.microsoft.com/schemas/adventure-works/products" 
xmlns:prod="http://www.microsoft.com/schemas/adventure-works/products"> 
<xs:element name="Product"> 
<xs:complexType> 
<xs:sequence> 
<xs:element ref="prod:ProductID" /> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="ProductID" type="xs:integer" /> 
</xs:schema> 
';
GO

将 xml 架构绑定(bind)到表:

CREATE TABLE ProductDocs
(
    ID INT IDENTITY PRIMARY KEY,
    ProductDoc XML(ManuInstructionsSchemaCollection)
);

将 Xml 数据插入表中:

INSERT INTO ProductDocs
    VALUES(
        N'<Product> 
        <ProductID>1</ProductID> 
    </Product>');

但是,然后它给出了错误:

XML Validation: Declaration not found for element 'Product'. Location: /*:Product[1]

我是否正确绑定(bind)架构?我已经搜索了很多,但我无法弄清楚这些事情。如有任何帮助,我们将不胜感激。

最佳答案

尝试像这样定义您的架构。

CREATE XML SCHEMA COLLECTION ManuInstructionsSchemaCollection AS
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > 
<xs:element name="Product"> 
<xs:complexType> 
<xs:sequence> 
<xs:element ref="ProductID" /> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="ProductID" type="xs:integer" /> 
</xs:schema>
';

关于sql-server - sql服务器: Bind Xml schema to a column of a Table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24993524/

相关文章:

sql - 获取具有相同 "Text"但不同 "Code"的记录

sql-server - 为什么我损坏的存储过程被删除了?

c# - 返回结束晚于 10 天的拍卖

java - 为什么 getLocalName() 返回 null?

java - 我的 AutoCompleteTextView 的 textColor 总是白色

sql-server - SQL Server : pause a trigger

sql-server - 如何在SQL 2008 R2中记录警告(严重性错误)

sql-server - T-SQL。过程调用的文本

r - 我如何在 R-Bloggers 上获取我的 blogdown 博客?

xml - 在 xml 字符串中突出显示父项