,,,
, SQL XML. XML MS SQL Server ADO. , XML SQL Server . , XML SQL Server , . , SQLXML 3.0, SQL Server Web-. , , , , .
, .
XML Microsoft SQL Server 2000
Microsoft SQL Server 2000 XML. XML for xml select, XML OPENXML.
FOR XML
XML-. :
[ FOR { BROWSE | XML { RAW | AUTO | EXPLICIT } [ , XMLDATA ] [ , ELEMENTS ] [ , BINARY BASE64 ] } ] |
BROWSE .
FOR XML RAW <row/>. , .
FOR XML AUTO XML , XML RAW, , , .
FOR XML EXPLICIT XML-. , . .
XMLDATA , . XML. , , , (validity). () . SQL Server XDR- (XML Data Reduced). XDR [1]. XMLDATA XML- (raw, auto explicit).
ELEMENTS , FOR XML AUTO. : , .
BINARY BASE64 , (binary data).
SQL Server GROUP BY FOR XML AUTO. |
PUBS SQL Server 2000. , Query Analyzer XML-, .. , ( , , ). , , IIS XML- SQL Server.
FOR XML RAW:
select au_fname, au_lname, address from authors where au_fname like 'M%' for xml raw |
, M. XML:
<row au_fname="Marjorie" au_lname="Green" address="309 63rd St. #411" /> <row au_fname="Michael" au_lname="O'Leary" address="22 Cleveland Av. #14" /> <row au_fname="Meander" au_lname="Smith" address="10 Mississippi Dr." /> <row au_fname="Morningstar" au_lname="Greene" address="22 Graybar House Rd." /> <row au_fname="Michel" au_lname="DeFrance" address="3 Balding Pl." /> |
xml raw xml auto:
<authors au_fname="Marjorie" au_lname="Green" address="309 63rd St. #411" /> <authors au_fname="Michael" au_lname="O'Leary" address="22 Cleveland Av. #14" /> <authors au_fname="Meander" au_lname="Smith" address="10 Mississippi Dr." /> <authors au_fname="Morningstar" au_lname="Greene" address="22 Graybar House Rd." /> <authors au_fname="Michel" au_lname="DeFrance" address="3 Balding Pl." /> |
, . row . ELEMENTS.
select au_fname, au_lname, address from authors where au_fname like 'M%' for xml auto, elements |
:
<authors> <au_fname>Marjorie</au_fname> <au_lname>Green</au_lname> <address>309 63rd St. #411</address> </authors> <authors> <au_fname>Michael</au_fname> <au_lname>O'Leary</au_lname> <address>22 Cleveland Av. #14</address> </authors> <authors> <au_fname>Meander</au_fname> <au_lname>Smith</au_lname> <address>10 Mississippi Dr.</address> </authors> <authors> <au_fname>Morningstar</au_fname> <au_lname>Greene</au_lname> <address>22 Graybar House Rd.</address> </authors> <authors> <au_fname>Michel</au_fname> <au_lname>DeFrance</au_lname> <address>3 Balding Pl.</address> </authors> |
: .
XMLDATA .
select au_fname, au_lname, address from authors where au_fname like 'M%' for xml auto, xmldata |
:
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <ElementType name="authors" content="empty" model="closed"> <AttributeType name="au_fname" dt:type="string" /> <AttributeType name="au_lname" dt:type="string" /> <AttributeType name="address" dt:type="string" /> <attribute type="au_fname" /> <attribute type="au_lname" /> <attribute type="address" /> </ElementType> </Schema> <authors xmlns="x-schema:#Schema1" au_fname="Marjorie" au_lname="Green" address="309 63rd St. #411" /> <authors xmlns="x-schema:#Schema1" au_fname="Michael" au_lname="O'Leary" address="22 Cleveland Av. #14" /> <authors xmlns="x-schema:#Schema1" au_fname="Meander" au_lname="Smith" address="10 Mississippi Dr." /> <authors xmlns="x-schema:#Schema1" au_fname="Morningstar" au_lname="Greene" address="22 Graybar House Rd." /> <authors xmlns="x-schema:#Schema1" au_fname="Michel" au_lname="DeFrance" address="3 Balding Pl." /> |
, DR-, .
FOR XML EXPLICIT
; XML- . , , .
tag . . , , . parent . . , 0 NULL. , UNION ALL.
tag parent , . , XML-, . :
ElementName!TagNumber!AttributeName!Directive |
:
ElementName , . .
TagNumber , . ElementName TagNumber. , .
AttributeName ( ), .
Directive , . :
element | |
xml | , element, . , (<) < |
cdata | . . |
hide | |
id,idref,idrefs | . , . |
. FOR XML RAW:
select au_fname,au_lname,address from authors where au_fname like 'M%' for xml raw |
FOR XML EXPLICIT:
select 1 as tag, 0 as parent, au_fname as 'authors!1!fname', au_lname as 'authors!1!lname', address as 'authors!1!address' from authors where au_fname like 'M%' for xml explicit |
. FOR XML EXPLICIT.
select 1 as tag, 0 as parent, au_fname as 'authors!1!fname', au_lname as 'authors!1!lname!element', address as 'authors!1!!cdata' from authors where au_fname like 'M%' for xml explicit |
:
<authors lname="Green"> <fname>Marjorie</fname> <![CDATA[ 309 63rd St. #411 ]]> </authors> <authors lname="O'Leary"> <fname>Michael</fname> <![CDATA[ 22 Cleveland Av. #14 ]]> </authors> <authors lname="Smith"> <fname>Meander</fname> <![CDATA[ 10 Mississippi Dr. ]]> </authors> <authors lname="Greene"> <fname>Morningstar</fname> <![CDATA[ 22 Graybar House Rd. ]]> </authors> <authors lname="DeFrance"> <fname>Michel</fname> <![CDATA[ 3 Balding Pl. ]]> </authors> |
! au_lname element, . CDATA.
, . :
select pub_name,city,fname,lname from publishers as p join employee as e on p.pub_id = e.pub_id where pub_name like 'Binnet%' or pub_name like 'New Moon%' order by pub_name,city,fname,lname |
Binnet & Hardley New Moon Books. (20 ) , , , .. . :
<pubs PubName="Binnet & Hardley" City="Washington"> <employee First_Name="Anabela" Last_Name="Domingues" /> <employee First_Name="Daniel" Last_Name="Tonini" /> <employee First_Name="Elizabeth" Last_Name="Lincoln" /> <employee First_Name="Helen" Last_Name="Bennett" /> <employee First_Name="Lesley" Last_Name="Brown" /> <employee First_Name="Martine" Last_Name="Rance" /> <employee First_Name="Paolo" Last_Name="Accorti" /> <employee First_Name="Paul" Last_Name="Henriot" /> <employee First_Name="Peter" Last_Name="Franken" /> <employee First_Name="Victoria" Last_Name="Ashworth" /> </pubs> <pubs PubName="New Moon Books" City="Boston"> <employee First_Name="Gary" First_Name="Thomas" /> <employee First_Name="Howard" First_Name="Snyder" /> <employee First_Name ="Karin" First_Name="Josephs" /> <employee First_Name ="Laurence" Last_Name="Lebihan" /> <employee First_Name ="Martin" Last_Name="Sommer" /> <employee First_Name ="Mary" Last_Name="Saveley" /> <employee First_Name ="Matti" Last_Name="Karttunen" /> <employee First_Name ="Palle" Last_Name="Ibsen" /> <employee First_Name ="Roland" Last_Name="Mendel" /> <employee First_Name ="Timothy" Last_Name="O'Rourke" /> </pubs> |
, ? :
select 1 as tag, -- 0 as parent, pub_name as 'pubs!1!PubName', city as 'pubs!1!City', NULL as 'employee!2!First_Name', NULL as 'employee!2!Last_Name' from publishers as pubs where pub_name like 'Binnet%' or pub_name like 'New Moon%' union all select 2 as tag, -- 1 as parent, pubs.pub_name, pubs.city, fname, lname from employee as e, publishers as pubs where (pub_name like 'Binnet%' or pub_name like 'New Moon%') and pubs.pub_id = e.pub_id order by 'pubs!1!PubName', 'pubs!1!City', 'employee!2!First_Name', 'employee!2!Last_Name' for xml explicit |
. . 1.
tag | parent | pubs!1!PubName | pubs!1!City | employee!2!First_Name | employee!2!Last_Name |
1 | 0 | New Moon Books | Boston | NULL | NULL |
1 | 0 | Binnet & Hardley | Washington | NULL | NULL |
1.
( 2).
tag | parent | pub_name | city | fname | lname |
2 | 1 | Binnet & Hardley | Washington | Paolo | Accorti |
2 | 1 | Binnet & Hardley | Washington | Victoria | Ashworth |
2 | 1 | Binnet & Hardley | Washington | Helen | Bennett |
2 | 1 | Binnet & Hardley | Washington | Lesley | Brown |
... | ... | ... | ... | ... | ... |
2.
, tag parent SQL Server XML .
FOR XML EXPLICIT. . |
, , FOR XML EXPLICIT .
OPENXML
OPENXML OPENROWSET, OPENDATASOURCE OPENQUERY, . :
OPENXML(idoc int [in],rowpattern nvarchar[in],[flags byte[in]]) [WITH (SchemaDeclaration | TableName)] |
:
idoc XML-, sp_xml_preparedocument;
rowpattern XPath , , XPath-;
flags , , XML ;
ShemaDeclaration :
ColName ColType [ColPattern | MetaProperty] |
ColName .
ColType . SQL Server.
ColPattern - XPath .
MetaProperty . .
XML- sp_xml_preparedocument. MSXML . OPENXML sp_xml_removedocument.
sp_xml_preparedocument XML-, DOM (Document Object Model). , . |
, . SQL Server XML- "edge table"-. , . , , , . XML-:
<?xml version="1.0" encoding="windows-1251" ?> <rsdn> <forums date="09.01.03"> <forum name="WinAPI" totalposts="16688" description=" "> <moderators/> <top-poster>Alex Fedotov</top-poster> </forum> <forum name="COM" totalposts="10116" description=" "> <moderators/> <top-poster>Vi2</top-poster> </forum> <forum name="Delphi" totalposts="5001" description="Delphi Builder"> <moderators> <moderator name="Sinclair"/> <moderator name="Hacker_Delphi"/> </moderators> <top-poster>Sinclair</top-poster> </forum> <forum name="DB" totalposts="6606" description=" "> <moderators> <moderator name="_MarlboroMan_"/> </moderators> <top-poster>Merle</top-poster> </forum> </forums> </rsdn> |
, :
exec sp_xml_preparedocument @hdoc out, @_xmlbody select [text] as totalposts from openxml(@hdoc,'/rsdn/forums/forum') as f join (select [id],localname from openxml(@hdoc,'/rsdn/forums/forum') where localname = 'totalposts') as d on d.[id] = f.parentid exec sp_xml_removedocument @hdoc |
:
totalposts |
16688 |
10116 |
5001 |
6606 |
, , ( , XML- ). , XPath.
exec sp_xml_preparedocument @hdoc out, @_xmlbody select * from openxml(@hdoc,'/rsdn/forums/forum') with(totalposts varchar(100) 'attribute::totalposts') exec sp_xml_removedocument @hdoc |
, , XPath-.
attribute::totalposts , totalposts . XPath- :
attribute:: @;
self::node() (.);
parent::node() (..).
XPath.
: , , 6000 .
exec sp_xml_preparedocument @hdoc out, @_xmlbody select forum as '', case when moders is null then '' else moders end as '', [date] as ' ' from openxml(@hdoc,'/rsdn/forums/forum[attribute::totalposts > "6000"]') with ( moders varchar(50) 'moderators/moderator/attribute::name', forum varchar(50) 'attribute::name', [date] varchar(50) 'parent::node()/attribute::date' ) exec sp_xml_removedocument @hdoc |
, XPath, :
openxml(@hdoc,'/rsdn/forums/forum[@totalposts > "6000"]') with ( moders varchar(50) 'moderators/moderator/@name', forum varchar(50) '@name', [date] varchar(50) '../@date' ) |
.
OPENXML, MSDN:
DECLARE @idoc int DECLARE @doc varchar(1000) SET @doc =' <root> <Customer cid= "C1" city="Issaquah"> <name>Janine</name> <Order oid="O1" date="1/20/1996" amount="3.5" /> <Order oid="O2" date="4/30/1997" amount="13.4"> Customer was very satisfied </Order> </Customer> <Customer cid="C2" city="Oelde" > <name>Ursula</name> <Order oid="O4" date="1/20/1996" amount="10000">Happy Customer.</Order> <Order oid="O3" date="7/14/1999" amount="100" note="Wrap it blue white red"> Sad Customer. <Urgency>Important</Urgency> </Order> </Customer> </root>' -- XML-. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc SELECT * FROM OPENXML (@idoc, '/root/Customer', 2) WITH ( cid char(5) '@cid', [name] varchar(20), oid char(5) 'Order/@oid', amount float 'Order/@amount', comment varchar(100) 'Order/text()' ) -- EXEC sp_xml_removedocument @idoc |
:
cid | name | oid | amount | comment |
C1 | Janine | O1 | 3.5 | Customer was very satisfied |
C2 | Ursula | O4 | 10000.0 | Happy Customer. |
:
XML- 2 (element-centric mapping). , XML-. , 0, 1 8. 0 attribute-centric mapping. 1, , . 1 2 "", .. 3, , , ( ) ( NULL). , 2, cid XPath-, , cid. name XPath-. 1 ( ), : .. cid , name (.. name).
XPath- , , XML- ( ). , , , . comment varchar(100) 'Order/text()' comment varchar(100) 'Order', comment . (O1). , text() false, Order ( O2). , . , .
OPENXML. MSDN. XPath [2].
IIS XML SQL Server
SQL Server HTTP, -. "Configure SQL XML Support in IIS". , [3]. , VDirMgr. sqlvdr3.dll. VB Microsoft SQL Virtual Directory Control 1.0 Type Library.
"Configure SQL XML Support in IIS" , isapi-: sqlisapi.dll. , SQL OLEDB, SQL Server . , XML, HTTP. :
SQL Server Windows, ;
, SQL Server ;
(, ). : schema, template dbobject. schema XDR XSD , URL-. template , URL-. dbobject , .
SQLXML 3.0 soap. . |
. :
SQL- URL. , , . , .
, . .
XPath;
POST.
URL-
URL- SQL Server:
http://iisserver/vroot?sql=sqlinstruction[¶m=value[¶m=value]...n] |
:
iisserver -;
vroot ;
sqlinstruction SQL-;
param . SQL- , : contenttype, outputencoding, root xsl;
value .
, , PUBS server_pubs. , server. URL-:
http://server/server_pubs/?sql=select au_fname, au_lname, address from authors where au_fname like 'M%' for xml raw |
. :
XML document must have a top level element. |
, , ! , XML-, SQL Server, , . root.
http://server/server_pubs/?sql=select au_fname,au_lname,address from authors where au_fname like 'M%' for xml raw&root=my_root |
:
Incorrect syntax near 'M'. |
, , , . URL, 25. , :
http://server/server_pubs/?sql=select au_fname,au_lname,address from authors where au_fname like 'M%25' for xml raw&root=my_root |
! . , .
, HTML, XSL URL xsl. .
:
<?xml version="1.0" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match = "*"> <xsl:apply-templates /> </xsl:template> <xsl:template match = "row"> <li> <table><tr> <td><xsl:value-of select = "attribute::au_fname" /></td> <td><xsl:value-of select = "attribute::au_lname" />.</td> <td>Address: <xsl:value-of select = "attribute::address" /></td> </tr></table> </li> </xsl:template> <xsl:template match = "/"> <html> <body> <ul> <xsl:apply-templates select = "my_root" /> </ul> </body> </html> </xsl:template> </xsl:stylesheet> |
XSL [4].
URL- XML-.
http://server/server_pubs/?sql=select au_fname,au_lname,address from authors where au_fname like 'M%25' for xml raw&root = my_root&xsl = xsl_for_query.xsl |
URL- . , , URL- . .
XML-, . SQL- . XPath, . URL-. , <param>.
, , URL-. ISAPI-, , , , . template. "Configure SQL XML Support in IIS" Virtual Names.
:
<?xml version="1.0" ?> <your_root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:xsl="xsl file name"> <xql:header> <xql:param name="your_param_name"> param_value </sql:param> <xql:param name="your_param_name"> param_value </sql:param>...n </xql:header> <sql:query> SQL- </sql:query> </your_root> |
XSL-. xsl, , . xsl , header.
, .
<?xml version="1.0" ?> <my_root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:xsl="xsl_for_query.xsl"> <sql:query> select au_fname,au_lname,address from authors where au_fname like 'M%' for xml raw </sql:query> </my_root> |
, . (, first_template.xml):
http://server/server_pubs/template/first_template.xml |
: IE HTML- ( ) XML. , - HTML, . contenttype.
http://server/server_pubs/template/first_template.xml?contenttype=text/html |
:
, ;
;
;
, - ;
XPath, .
( ):
client-side-xml , 0 1. 1, XML- . .. SQL Server , , . ADO XML.
, SQL Server-y, , SQLXMLOLEDB-. ADO . IIS. |
nullvalue , URL- XPath NULL.
is-xml , 0 1, header. 1. , xml, , , < . 0, .
MSDN.
XPath
XPath . XPath- , XDR XSD. XDR Microsoft, .. , , , . XSD XDR .
XSD [5]. |
: XML- , XPath. , , XML- . SQLXML 2.0 SDR [6]. XSD [7]. XDR XSD [8].
XPath:
<your_root xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:header> <xql:param name="your_param_name"> param_value </sql:param> <xql:param name="your_param_name"> param_value </sql:param>...n </sql:header> <sql:xpath-query mapping-schema="your_schema.xml"> XPath query </sql:xpath-query> </your_root> |
your_schema.xml. , XPath. $.
XDR, XPath. , :
<?xml version="1.0" ?> <Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:sql="urn:schemas-microsoft-com:xml-sql" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <ElementType name="address" /> <ElementType name="Authors" sql:relation="Authors"> <AttributeType name="au_fname" dt:type="string" /> <AttributeType name="au_lname" dt:type="string" /> <attribute type="au_fname"/> <attribute type="au_lname" /> <element type="address" sql:field="address"/> </ElementType> </Schema> |
relation , , Authors. , ElementType. (view) , field. AttributeType , .. . ElementType, , . .
. , MySchema.xml.
IIS XML- , . IIS , . . , template , schema . |
, , :
<my_root xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:xpath-query mapping-schema="../Schema/MySchema.xml"> /Authors </sql:xpath-query> </my_root> |
XDR XSD, XSD.
, XPath XSD-. ISAPI- XPath: unable to find /authors in the schema. , www.sql.ru, . : mmc SQL IIS Admin.MSC, MS SQL Server SQLXML 3.0. %Program Files%SQLXML 3.0 sqlisad3.msc. Start->Programs->SQLXML 3.0->Configure IIS Support. . |
XDR XSD[9], :
XDR | XSD |
Schema | schema |
ElementType | element |
AttributeType | attribute |
attribute | none |
:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="authors" sql:relation="authors"> <xsd:complexType> <xsd:attribute name="au_fname" sql:field="au_fname" /> <xsd:attribute name="au_lname" sql:field="au_lname" /> <xsd:attribute name="address" sql:field="address" /> </xsd:complexType> </xsd:element> </xsd:schema> |
, XML- authors . , . . SQLXML . , . :
<?xml version="1.0" encoding="windows-1251" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="" sql:relation="authors"> <xsd:complexType> <xsd:sequence> <xsd:element name="" sql:field="au_lname"/> <xsd:element name="" sql:field="address" /> </xsd:sequence> <xsd:attribute name="" sql:field="au_fname"/> </xsd:complexType> </xsd:element> </xsd:schema> |
, schema, XPath-, URL. , root.
http://server/server_pubs/schema/xsd_map_schema.xml/?root=root |
, :
relationship , . XML-.
is-constant , .
map-field , 0 1. 0 , . SQLXML 3.0 mapped.
limit-field limit-value , . WHERE.
use-cdata , XML- CDATA . url-encode ID, IDREF, IDREFS, NMTOKEN NMTOKENS.
hide , 0 1. , XML- ( 0) XML-, XPath. mapped. , mapped XML- , XPath.
, . FOR XML EXPLICIT , . XML- :
<?xml version="1.0" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <xsd:annotation> <xsd:appinfo> <sql:relationship name="PubsEmployees" parent="publishers" parent-key="pub_id" child="employee" child-key="pub_id" /> </xsd:appinfo> </xsd:annotation> <xsd:element name="pubs" sql:relation="publishers"> <xsd:complexType> <xsd:sequence> <xsd:element name="employee" sql:relation="employee" sql:relationship="PubsEmployees" > <xsd:complexType> <xsd:attribute name="First_Name" sql:field="fname" type="xsd:string" /> <xsd:attribute name="Last_Name" sql:field="lname" type="xsd:string" /> <xsd:attribute name="minit" sql:field="minit" type="xsd:string" sql:hide="1" /> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="PubName" sql:field="pub_name" type="xsd:string"/> <xsd:attribute name="City" sql:field="city" type="xsd:string" sql:limit-field="pub_name" sql:limit-value="Binnet & Hardley" /> </xsd:complexType> </xsd:element> </xsd:schema> |
hide XML- , XPath-. limit-field limit-value Binnet & Hardley. xsd:annotation , <xsd:element name="employee">. relationship .
:
http://server/server_pubs/schema/schema1.xml/pubs/employee[@minit=""]?root=root |
. :
<?xml version="1.0" encoding="windows-1251" ?> <my_root xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ms="urn:schemas-microsoft-com:mapping-schema" id="InLineSchema1" sql:is-mapping-schema="1"> <xsd:element name="" ms:relation="authors"> <xsd:complexType> <xsd:attribute name="" ms:field="au_fname"/> <xsd:attribute name="" ms:field="au_lname"/> <xsd:attribute name="" ms:field="address"/> </xsd:complexType> </xsd:element> </xsd:schema> <sql:xpath-query mapping-schema="#InLineSchema1"> / </sql:xpath-query> </my_root> |
XPath , XML, is-mapping-schema. 0 1. , , . id mapping-schema .
, . , Microsoft XML View Mapper. http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/443/msdncompositedoc.xml . ; , . XSD. , .
, SQL Server 2000 XPath XPath- . .
XPath:
(axis) | attribute, child, parent, and self |
=, !=, <, <=, >, >= | |
+, -, *, div | |
number(), string(), Boolean() | |
And, or | |
true(), false(), not() |
:
ancestor, ancestor-or-self, descendant, descendant-or-self (//), following, following-sibling, namespace, preceding, preceding-sibling | |
Mod | |
string(), concat(), starts-with(), contains(), substring-before(), substring-after(), substring(), string-length(), normalize(), translate() | |
lang() | |
sum(), floor(), ceiling(), round() | |
| |
(query) XPath (XPath-query) , .
(query) SQL-. , . XML Bulk Load.
urn:schemas-microsoft-com:xml-sql | XDR |
urn:schemas-microsoft-com:xml-data | XDR |
http://www.w3.org/2001/XMLSchema | XSD |
urn:schemas-microsoft-com:mapping-schema | XSD |
ADO XML
XML- ADO Recordset XML. Recordset adPersistADTG. RDS (Remote Data Services). OLE DB Persistence Provider. , () Recordset . XML XML- .
OLE DB Persistence Provider XML-: XDR, data, row. row. , - . , , XSLT, .
ADO 2.5 IStream. : DOMDocument, XML- transformNode, , . , Response ASP, adPersistADTG, adPersistXML. ADO 2.5 Stream (, IStream). (LoadFromFile SaveToFile), (ReadText WriteText) . , .
ADO 2.5
XML
, . vbs-:
Const adopenStatic = 3 Const adLockReadOnly = 1 Const adCmdText = 1 Const adPersistXML = 1 Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "select au_fname,au_lname,address from authors where au_fname like 'M%'", _ "Provider=sqloledb;Data Source=server;Initial Catalog=pubs;" & _ "User Id=user;Password=password;", adopenStatic, adLockReadOnly, adCmdText rs.Save "c:myrs.xml", adPersistXML |
XML- Recordset:
Const adopenStatic = 3 Const adLockReadOnly = 1 Const adCmdFile = 256 Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "c:myrs.xml", "Provider=MSPersist;", adopenStatic, adLockReadOnly, adCmdFile |
DOMDocument
ASP-, Recordset DOMDocument. , HTML . , URL-. ASP:
<% ' Define some constant for ADO. Const adopenStatic = 3 Const adLockReadOnly = 1 Const adCmdText = 1 Const adPersistXML = 1 ' Creating objects Dim rs,dom,stylesheet Set dom = Server.CreateObject("MSXML2.DOMDocument") Set stylesheet = Server.CreateObject("MSXML2.DOMDocument") Set rs = Server.CreateObject("ADODB.Recordset") ' Open recordset rs.Open "select au_fname,au_lname,address from authors where au_fname like 'M%'", _ "Provider=sqloledb;Data Source=server;Initial Catalog=pubs;" & _ "User Id=user;Password=password;", adopenStatic, adLockReadOnly, adCmdText ' Save recordset to DOMDocument rs.Save dom,adPersistXML ' Loading stylesheet stylesheet.async = false stylesheet.load "C:Inetpubwwwrootserver_pubsformat_for_ado.xsl" ' Perform transformation Response.Write dom.transformNode(stylesheet) ' Cleanup Set dom = nothing Set stylesheet = nothing Set rs = nothing %> |
:
<?xml version="1.0" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0"> <xsl:template match = "*"> <xsl:apply-templates /> </xsl:template> <xsl:template match = "z:row"> <li> <table><tr> <td><xsl:value-of select = "@au_fname" /></td> <td><xsl:value-of select = "@au_lname" />.</td> <td>Address: <xsl:value-of select = "@address" /></td> </tr></table> </li> </xsl:template> <xsl:template match = "/"> <html> <body> <ul> <xsl:apply-templates select = "xml/rs:data" /> </ul> </body> </html> </xsl:template> </xsl:stylesheet> |
Recordset XML Response
Response ASP.
<% ' Should specify this Response.ContentType = "text/xml" ' Define some constant for ADO. Const adopenStatic = 3 Const adLockReadOnly = 1 Const adCmdText = 1 Const adPersistXML = 1 Dim rs Set rs = Server.CreateObject("ADODB.Recordset") ' Open recordset rs.Open "select au_fname,au_lname,address from authors where au_fname like 'M%'", _ "Provider=sqloledb;Data Source=server;Initial Catalog=pubs;" & _ "User Id=user;Password=password;", adopenStatic, adLockReadOnly, adCmdText ' Save recordset to Response stream rs.Save Response,adPersistXML Set rs = nothing %> |
. RDS.DataControl.
, RDS adPersistADTG, XML . |
MSDN :
<HTML> <HEAD><TITLE> ADO Recordset Persistence</TITLE></HEAD> <BODY> <OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33" ID="RDC1" <PARAM NAME="URL" VALUE="http://yourserver/XMLPersist/XMLResponse.asp"> </OBJECT> <TABLE DATASRC="#RDC1"> <TR> <TD><SPAN DATAFLD="au_fname"></SPAN></TD> <TD><SPAN DATAFLD="au_lname"></SPAN></TD> <TD><SPAN DATAFLD="address"></SPAN></TD> </TR> </TABLE> </BODY> </HTML> |
( vbs):
Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "http://server/server_dir/sql2xml.asp" |
ADO 2.6
Command SQL-, XML- XPath. Dialect. [10].
ADO | |
Transact-SQL | {C8B522D7-5CF3-11CE-ADE5-00AA0044773D} |
XPath | {EC2A4293-E898-11D2-B1B7-00C04F680C56} |
XML- | {5D531CB2-E6Ed-11D2-B252-00C04F681B71} |
{C8B521FB-5CF3-11CE-ADE5-00AA0044773D} |
Command , Recordset. Output Stream : Command ( , IStream). , ( CommandText) XPath, - . Mapping Schema. .
Command XML-
, XML- ADO:
<% ' ADO. Const adopenStatic = 3 Const adLockReadOnly = 1 Const adCmdText = 1 Const adPersistXML = 1 Const adExecuteStream = &H400 ' Dim cmd,conn Set cmd = Server.CreateObject("ADODB.Command") Set conn = Server.CreateObject("ADODB.Connection") conn.Provider = "sqloledb" conn.Open "Data Source=server;Initial catalog=pubs;", "user", "password" Set cmd.ActiveConnection = conn cmd.CommandType = adCmdText cmd.CommandText = "select au_fname, au_lname, address " _ & "from authors where au_fname like 'M%' for xml auto" cmd.Properties("Output Stream") = Response cmd.Properties("xml root") = "root" cmd.Execute , , adExecuteStream Set cmd = nothing Set conn = nothing %> |
FOR XML AUTO XML- SQL Server. , xml root. Response. ASP- , , : XML- , .
( ASP):
<% ' : Response.ContentType = "text/xml" ' ADO. Const adCmdText = 1 Const adExecuteStream = &H400 ' Dim cmd,conn Set cmd = Server.CreateObject("ADODB.Command") Set conn = Server.CreateObject("ADODB.Connection") conn.Provider = "sqloledb" conn.Open "Data Source=server;Initial catalog=pubs;", "user","password" ' Dim s s = "<?xml version='1.0' ?>" & _ "<my_root xmlns:sql='urn:schemas-microsoft-com:xml-sql'>" & _ "<sql:query>" & _ "select au_fname,au_lname,address from authors " & _ "where au_fname like 'M%' for xml auto" & _ "</sql:query>" & _ "</my_root>" Set cmd.ActiveConnection = conn cmd.CommandType = adCmdText cmd.CommandText = s ' cmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}" cmd.Properties("Output Stream") = Response cmd.Execute , , adExecuteStream Set cmd = nothing Set conn = nothing %> |
XPath
ADO XPath, , XDR-. vbs, :
' ADO. Const adCmdText = 1 Const adExecuteStream = &H400 ' Dim cmd,conn,cmdStream Dim ie Set ie = CreateObject("InternetExplorer.Application") ie.Navigate "about:blank" Set cmd = CreateObject("ADODB.Command") Set conn = CreateObject("ADODB.Connection") Set cmdStream = CreateObject("ADODB.Stream") conn.Provider = "sqloledb" conn.Open "Data Source=server;Initial catalog=pubs;", "user", "password" cmdStream.Open Set cmd.ActiveConnection = conn cmd.CommandType = adCmdText ' XPath- cmd.CommandText = "" ' XPath cmd.Dialect = "{EC2A4293-E898-11D2-B1B7-00C04F680C56}" cmd.Properties("Base Path") = "C:Inetpubwwwrootserver_pubs" cmd.Properties("Output Stream") = cmdStream ' cmd.Properties("Mapping Schema") = "schemamyschema.xml" ' cmd.Properties("XSL") = "templatefirst_select.xsl" cmd.Properties("xml root") = "my_root" cmd.Execute , , adExecuteStream Dim str str = cmdStream.ReadText do loop while ie.Busy ie.Document.writeln CStr(str) ie.Document.close ie.visible = 1 |
.
:
<?xml version="1.0" encoding="windows-1251" ?> <Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:sql="urn:schemas-microsoft-com:xml-sql" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <ElementType name="" sql:relation="authors"> <AttributeType name="" dt:type="string" /> <AttributeType name="" dt:type="string" /> <AttributeType name="" dt:type="string" /> <attribute type="" sql:field="au_fname" /> <attribute type="" sql:field="au_lname" /> <attribute type="" sql:field="address" /> </ElementType> </Schema> |
:
<?xml version="1.0" encoding="windows-1251" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match = "*"> <xsl:apply-templates /> </xsl:template> <xsl:template match = "/"> <html> <body> <table border="1" style="table-layout:fixed" width="600"> <tr bgcolor="teal"> <th><font color="white"></font></th> <th><font color="white"></font></th> <th><font color="white"></font></th> </tr> <xsl:for-each select="my_root/"> <tr> <td><font color="teal"><xsl:value-of select="@"/></font></td> <td><font color="teal"><xsl:value-of select="@"/></font></td> <td><font color="teal"><xsl:value-of select="@"/></font></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> |
XML-
, SQL Server , , XML-. : XML DOMDocument - . , , , , . -, XML- . -, XDR, . XPath-. ( ) SQLXMLOLEDB. (, MSDataShape) . SQLXMLOLEDB SQL-, . , SQLXMLOLEDB SQLOLEDB- SQL Server, ( , ) , , MSDAORA ( Oracle). , XML- , XML .
XML- GROUP BY , XML- ( FOR XML AUTO). , SQLXMLOLEDB . , , , , MSDataShape , , :
FOR XML RAW | FOR XML RAW |
FOR XML NESTED | FOR XML AUTO |
FOR XML EXPLICIT | FOR XML EXPLICIT |
1.
1.
GROUP BY FOR XML AUTO (NESTED) | ||
MSDN. .
FOR XML NESTED client-side-xml. . client-side-xml 1, .
<?xml version="1.0" ?> <my_root xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:query client-side-xml="1"> select count(*) as number_of_authors,city from authors group by city order by number_of_authors desc for xml nested </sql:query> </my_root> |
XML- ADO
Command ClientSideXML, XML- . :
<% Const adCmdText = 1 Const adExecuteStream = &H400 Response.ContentType = "text/xml" ' Creating the objects Dim conn,cmd Set conn = Server.CreateObject("ADODB.Connection") Set cmd = Server.CreateObject("ADODB.Command") conn.Provider = "sqlxmloledb" conn.Open "Data Source=server;Initial catalog=pubs;Data Provider=sqloledb", _ "user","password" Dim s s = "select count(*) as number_of_authors,city" & _ "from authors" & _ "group by city" & _ "order by number_of_authors desc" & _ "for xml nested" Set cmd.ActiveConnection = c cmd.Properties("ClientSideXML") = "True" cmd.CommandType = adCmdText cmd.CommandText = s cmd.Properties("Output Stream") = Response cmd.Properties("xml root") = "root" cmd.Execute , , adExecuteStream Set cmd = nothing Set conn = nothing %> |
SQLXMLOLEDB. SQL Server Data Provider=sqloledb. , , ClientSideXML true. , (.. ) adCmdText. .
XML Bulk Load
(, ) XML-. SQL- ? -, . , XML , SQL, . , , XML Bulk Load , XML-. .
, , . :
<your_root xmlns:updg="urn:schemas-microsoft-com:xml-updategram" [mapping-schema="your_schema.xml"]> <updg:header> <updg:param name="param1_name" /> <updg:param name="param2_name" /> </updg:header> <updg:sync> <updg:before> xml- </updg:before> <updg:after [updg:returnid="your_id"]> xml- </updg:after> </updg:sync> </your_root> |
, . , , URL , , . header , . before, , , . . . after , . . sync begin trans commit trans. rollback trans.
. , . |
? :
before , . , , age 33, Ambiguous delete, unique identifier required. , . Empty delete, no deletable rows found , Empty update, no updatable rows found .
.
(constraint violation).
SQL Server , , XDR XSD. , , .
after. before . identity, returned ( at-identity, . ). , , :
id ;
at-identity XML- identity. ,
create table test1(_id int identity,fld1 int) |
, :
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync> <updg:after updg:returnid="ident_field"> <test1 fld1="23" updg:at-identity="ident_field"/> </updg:after> </updg:sync> </ROOT> |
http://server/server_pubs/template/upd1.xml :
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <returnid><ident_field>1</ident_field></returnid> </ROOT> |
guid (GUID).
. :
<?xml version="1.0" encoding="windows-1251" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="" sql:relation="authors"> <xsd:complexType> <xsd:attribute name="" type="xsd:string" sql:field="au_fname" /> <xsd:attribute name="" type="xsd:string" sql:field="au_lname" /> <xsd:attribute name="" type="xsd:string" sql:field="au_id" /> <xsd:attribute name="" type="xsd:integer" sql:field="contract" default="1"/> </xsd:complexType> </xsd:element> </xsd:schema> |
, XML- . :
<?xml version="1.0" encoding="windows-1251" ?> <ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync mapping-schema="upd_schema.xml"> <updg:after> < ="alex" ="shirshov" ="123-15-3452"/> </updg:after> </updg:sync> </ROOT> |
( ) authors.
before , after .
:
<?xml version="1.0" encoding="windows-1251" ?> <ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync mapping-schema="upd_schema.xml"> <updg:before> < ="alex" ="shirshov" ="123-15-3452" updg:id="for_update"/> </updg:before> <updg:after> < ="" ="" ="123-15-3452" updg:id="for_update"/> < ="alex" ="shirshov" ="123-15-3453" updg:id="for_insert"/> </updg:after> </updg:sync> </ROOT> |
: , before ( ). , id, . ? after , : , . , after before id. 123-15-3452, .
, , before .
<?xml version="1.0" encoding="windows-1251" ?> <ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync mapping-schema="upd_schema.xml"> <updg:before> < ="alex" ="shirshov" ="123-15-3453"/> </updg:before> </updg:sync> </ROOT> |
123-15-3453.
, , . , . |
MSDN [10].
XML Bulk Load
, XML-, . , , , . DOMDocument , , SQL. DOM, . , , SQL . , ( ) . , . , XML- OPENXML . . , ? , text ntext OPENXML. , OPENXML DOM, . , , ! XML Bulk Load.
XML Bulk Load COM-, DLL, XML- SAX (Simple API for XML). , . XML Bulk Load , XML- , . , XDR XSD.
XML Bulk Load . :
ConnectionString ( SQLOLEDB).
ConnectionCommand ADODB.Connection.
BulkLoad true, () . false (. SchemaGen). true.
ErrorLogFile , .
Transaction true, XML Bulk Load . false.
TempFilePath , . , - . , Transaction true. %temp%.
SchemaGen true, . , SGDropTables. false.
SGDropTables true, . , false ( ).
KeepIdentity true, identity XML-, false SQL Server . false.
, bcp (bulk copy program , SQL Server, / / ) BULK LOAD. .
"", " " . XML Bulk Load.
:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ms="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="test-table" ms:relation="test1"> <xsd:complexType> <xsd:attribute name="identifier" ms:datatype="int" ms:field="_id"/> <xsd:attribute name="field1" ms:datatype="int" ms:field="fld1"/> </xsd:complexType> </xsd:element> </xsd:schema> |
test1 int _id fld1. XML- identifier field1.
:
Dim xbcp,adoStream Set xbcp = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.3.0") Set adoStream = CreateObject ("ADODB.Stream") adoStream.Open adoStream.WriteText "<root><test-table field1='145' identifier='1' /></root>" AdoStream.Position = 0 xbcp.ConnectionString = "Provider=sqloledb.1;Data Source=server;" & _ "database=pubs;User ID=user;Password=password;" xbcp.SchemaGen = true xbcp.SGDropTables = true xbcp.Transaction = true xbcp.ErrorLogFile = "c:error.log" xbcp.TempFilePath = "c:temp" xbcp.Execute "xbcp_schema.xml",adoStream |
XML-, Stream ADO. stream , .
. , . , . |
, - , . : test1 test2. .
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ms="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="test-table1" ms:relation="test1"> <xsd:complexType> <xsd:sequence> <xsd:element name="test-table2" ms:relation="test2"> <xsd:annotation> <xsd:appinfo> <ms:relationship parent="test1" parent-key="test1_id" child="test2" child-key="test1_id" /> </xsd:appinfo> </xsd:annotation> <xsd:complexType> <xsd:attribute name="identifier" ms:datatype="int" ms:field="test2_id"/> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="identifier" ms:datatype="int" ms:field="test1_id"/> <xsd:attribute name="field1" ms:datatype="int" ms:field="fld1"/> </xsd:complexType> </xsd:element> </xsd:schema> |
( vbs):
Dim xbcp,adoStream Set xbcp = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.3.0") Set adoStream = CreateObject ("ADODB.Stream") adoStream.Open adoStream.WriteText "<ROOT>" & _ "<test-table1 identifier='10' field1='345'>" & _ "<test-table2 identifier='1' />" & _ "</test-table1>" & _ "</ROOT>" AdoStream.Position = 0 xbcp.ConnectionString = "Provider=sqloledb.1;Data Source=server;" & _ "database=pubs;User ID=user;Password=password;" xbcp.SchemaGen = true xbcp.SGDropTables = true xbcp.Transaction = true xbcp.ErrorLogFile = "c:error.log" xbcp.TempFilePath = "c:temp" xbcp.Execute "xbcp_schema.xml",adoStream |
.
test1_id | field1 |
10 | 345 |
test1.
test1_id | test2_id |
10 | 1 |
test2.
, , , . XML- Microsoft, : SQL- . , Oracle 9i XML XMLType. SQL- XML XML- ( XPath) , , MS SQL Server[12]. , , SQL Server Web- (Oracle 9i ). , Microsoft , , XDR .
XDR
XPath
IIS SQL Server
XSL
XSD
SDR XPath
XSD XPath
XDR XSD
XML , , .
XML MS SQL Server 2000 , .
XML Bulk Load
XML Oracle 9i
Copyright (c) 2024 Stud-Baza.ru , , , .