sp_xml_preparedocument
来源:互联网 发布:淘宝耐克代购正品店铺 编辑:程序博客网 时间:2024/04/30 22:23
sp_xml_preparedocument
读取作为输入提供的可扩展标记语言 (XML) 文本,然后使用 MSXML 语法分析器 (Msxml2.dll) 对其进行分析,并提供分析后的文档供您使用。分析后的文档是 XML 文档中各节点(元素、特性、文本、注释等)的树型表示法。
sp_xml_preparedocument 返回一个句柄,可用于访问 XML 文档的新创建的内部表示方式。该句柄在连接到 Microsoft® SQL Server™ 2000 期间保持有效,直到重置连接或执行 sp_xml_removedocument 使句柄无效为止。
说明 分析过的文档存储在 SQL Server 2000 的内部高速缓存中。MSXML 语法分析器使用 SQL Server 可用总内存的八分之一。若要避免内存不足,请运行 sp_xml_removedocument 以释放内存。
语法
sp_xml_preparedocument hdoc OUTPUT
[, xmltext]
[, xpath_namespaces]
参数
hdoc
是新创建的文档的句柄。hdoc 的数据类型为 integer。
[xmltext]
是原 XML 文档。MSXML 语法分析器分析该 XML 文档。xmltext 是 text 类型(char、nchar、varchar、nvarchar、text 或 ntext)的参数。默认值是 NULL,在这种情况下,将创建空 XML 文档的内部表示法。
[xpath_namespaces]
指定 OPENXML 的行和列 XPath 表达式中所使用的命名空间声明。默认值是 <root xmlns:mp="urn:schemas-microsoft-com:xml-metaprop">。
xpath_namespaces 通过符合语法规则的 XML 文档的方式,为在 OPENXML 的 Xpath 表达式中使用的前缀提供命名空间 URI。xpath_namespaces 声明前缀必须用于引用命名空间 urn:schemas-microsoft-com:xml-metaprop,该命名空间提供有关分析后的 XML 元素的元数据。尽管可以使用此方法为元属性命名空间重新定义命名空间前缀,但此命名空间不会丢失。此前缀 mp 对 urn:schemas-microsoft-com:xml-metaprop 仍有效,即使 xpath_namespaces 不包含此类声明。xpath_namespaces 是 text 类型(char、nchar、varchar、nvarchar、text 或 ntext)的参数。
返回代码值
0(成功)或 >0(失败)
权限
执行权限默认授予 public 角色。
示例
A. 为符合语法规则的 XML 文档准备内部表示方式
下例返回作为输入提供的新创建的 XML 文档内部表示法的句柄。在对 sp_xml_preparedocument 的调用中,使用了默认命名空间前缀映射。
DECLARE @hdoc intDECLARE @doc varchar(1000)SET @doc ='<ROOT><Customer CustomerID="VINET" ContactName="Paul Henriot"> <Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00"> <OrderDetail OrderID="10248" ProductID="11" Quantity="12"/> <OrderDetail OrderID="10248" ProductID="42" Quantity="10"/> </Order></Customer><Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"> <Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00"> <OrderDetail OrderID="10283" ProductID="72" Quantity="3"/> </Order></Customer></ROOT>'--Create an internal representation of the XML document.EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc-- Remove the internal representation.exec sp_xml_removedocument @hdoc
B. 为带 DTD 的符合语法规则的 XML 文档准备内部表示方式
下例返回作为输入提供的新创建的 XML 文档内部表示法的句柄。存储过程根据文档中包含的 DTD 来验证装载的文档。在对 sp_xml_preparedocument 的调用中,使用了默认命名空间前缀映射。
DECLARE @hdoc intDECLARE @doc varchar(2000)SET @doc = '<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE root [<!ELEMENT root (Customers)*><!ELEMENT Customers EMPTY><!ATTLIST Customers CustomerID CDATA #IMPLIED ContactName CDATA #IMPLIED>]><root><Customers CustomerID="ALFKI" ContactName="Maria Anders"/></root>'EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc
C. 指定命名空间 URI
下例返回作为输入提供的新创建的 XML 文档内部表示法的句柄。在对 sp_xml_preparedocument 的调用中,保留了元属性命名空间映射的 mp 前缀,并将 xyz 映射前缀添加到了命名空间 urn:MyNamespace。
DECLARE @hdoc intDECLARE @doc varchar(1000)SET @doc ='<ROOT><Customer CustomerID="VINET" ContactName="Paul Henriot"> <Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00"> <OrderDetail OrderID="10248" ProductID="11" Quantity="12"/> <OrderDetail OrderID="10248" ProductID="42" Quantity="10"/> </Order></Customer><Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"> <Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00"> <OrderDetail OrderID="10283" ProductID="72" Quantity="3"/> </Order></Customer></ROOT>'--Create an internal representation of the XML document.EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc, '<root xmlns:xyz="run:MyNamespace"/>'
请参见
- sp_xml_preparedocument
- sp_xml_preparedocument
- sp_xml_preparedocument的使用
- sp_xml_preparedocument sp_xml_removedocument 使用 实例 解析
- 使用sp_xml_preparedocument处理XML文档
- SQL Server 的For XML及sp_xml_preparedocument
- SQL 中 sp_xml_preparedocument,openxml的使用
- 存储过程使用sp_xml_preparedocument处理XML文档的方法
- 使用sp_xml_preparedocument处理XML文档 保存到sqlserver中
- 传递: xml string到sql server时的sp_xml_preparedocument无法解析问题
- sp_xml_preparedocument OPENXML sp_xml_removedocument截取XML片段或指定格式的数据
- 传递 xml string到sql server时的sp_xml_preparedocument无法解析问题
- Lucene1.4终于成功了
- Open Source Software in C#
- C# Coding Style Guide
- 从何开始
- 强世功 - 权力、技术与反抗——重读《一九八四》
- sp_xml_preparedocument
- web 服务
- 活着
- .NET资源文件的创建、使用
- 使用资源文件
- 从Coding Fan到真正的技术专家
- Eclipse in Action 翻译
- 使用资源文件(二)
- Eclipse实践(1)