sp_xml_preparedocument的使用

來源:互聯網
上載者:User
  /*大部分資料來自SQL Server Books */

sp_xml_preparedocumentsp_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在操作含有中文字元的XML語句中的注意事項1.可以直接如下寫法DECLARE @idoc intEXEC sp_xml_preparedocument @idoc OUTPUT, N'<root><qy><city>南海</city></qy></root>' DECLARE @idoc intDECLARE @doc nvarchar(1000)set @doc=N'<root><qy><city>南海</city></qy></root>'EXEC sp_xml_preparedocument @idoc OUTPUT, @doc DECLARE @doc nvarchar(1000)必須字定義nvarchar類型,要是定義varchar就報錯,不能儲存建立如下語句有問題,不正確。DECLARE @idoc intDECLARE @doc varchar(1000)set @doc=N'<root><qy><city>南海</city></qy></root>'EXEC sp_xml_preparedocument @idoc OUTPUT, @doc 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.