SP_XML_PREPAREDOCUMENT
Read the Scalable Markup Language (XML) text provided as an input, then analyze it using the MSXML Syntax Analyzer (MSXML2.DLL) and provides you with the analysis. The analytical document is a tree type representation of each node (element, characteristics, text, annotation, etc.) in the XML document.
SP_XML_PREPAREDocument returns a handle that can be used to access the newly created internal representation of the XML document. The handle is kept valid during the connection to Microsoft® SQL ServerTM 2000 until the connection is reset or executes sp_xml_removedocument so that the handle is invalid.
Description The analyzed document is stored in the internal cache of SQL Server 2000. MSXML Syntax Analyzer uses SQL Server to use one-third of total memory. To avoid insufficient memory, run sp_xml_removedocument to release memory.
grammar
SP_XML_PREPAREDocument hdoc output [, xmltext] [, xpath_namespaces]
parameter
HDOC
It is a handle of the newly created document. HDOC's data type is Integer.
[xmltext]
It is the original XML document. MSXML Syntax Analyzer Analyzes the XML document. XMLText is the parameter of the Text Type (Char, Nchar, Varchar, NVarchar, Text, or Ntext). The default is NULL, in which case the internal representation of the empty XML document will be created.
[XPATH_NAMESPACES]]
Specifies the namespace declarations used in the row of OpenXML and column XPath expressions. The default is
Returns the code value
0 (success) or> 0 (failure)
Authority
Perform permissions The default is granted public roles.
Example
A. Prepare internal representation for XML documents that meet grammar rules
The following example returns the handle of the newly created XML document inside the input provided. In the call to sp_xml_preparedocument, the default namespace prefix mapping is used.
Declare @HDoc Int
Declare @doc varchar (1000)
Set @doc = '
Order>
Customer>
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. Prepare the internal representation for XML documents with DTD compliant grammar rules
The following example returns the handle of the newly created XML document inside the input provided. The stored procedure verifies the loaded document according to the DTD included in the document. In the call to sp_xml_preparedocument, the default namespace prefix mapping is used.
Declare @HDoc Int
Declare @doc varchar (2000)
Set @doc = '
XML Version = "1.0" encoding = "UTF-8"?>
DOCTYPE ROOT
[
]>
root> '
EXEC SP_XML_PREPAREDocument @HDoc output, @doc
C. Specify a namespace URI
The following example returns the handle of the newly created XML document inside the input provided. In the call to sp_xml_preparedocument, the MP prefix mapping the meta-attribute namespace is retained, and the XYZ mapping prefix is added to the namespace URN: MyNameSpace.
Declare @HDoc Int
Declare @doc varchar (1000) set @doc = '
ORDERDATE = "1996-07-04T00: 00: 00"> Order> Customer> ORDERDATE = "1996-08-16t00: 00: 00"> Order> Customer> Root> ' --Create an internal representation of the xml document. EXEC SP_XML_PREPAREDocument @HDoc output, @doc, ' See SP_XML_REMOVEDOCUMENT