RAW Mode


The RAW mode of FOR XML is just that; it presents every row of a database query result with the simplistic identifier <ROW> . All columns of the result set's row are returned as attributes of the row, like this:

 <row OrderID="10258" EmployeeID="1" ShipName="Ernst Handel" />  <row OrderID="10270" EmployeeID="1" ShipName="Wartian Herkku" /> 

Some people really like the simplicity of RAW mode, while others argue that the documents generated by this mode are just not rich enough XML documents. You'll have to decide.

The XMLDATA and BINARY BASE64 arguments to FOR XML are applicable in RAW mode. The XMLDATA argument causes the XML schema to be returned at the beginning of the document with the requested data as a declared namespace. The BINARY BASE64 argument must be specified so that binary data is returned in base64-encoded format; otherwise , the error shown in Listing 7.6 is generated.

Listing 7.7 is a template file utilizing a basic example of RAW mode; the results are given in Listing 7.8.

Listing 7.7 FOR XML RAW
 <ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>    <sql:query>      SELECT TOP 4 OrderID,EmployeeID, ShipName      FROM Orders      WHERE EmployeeID=1      FOR XML RAW    </sql:query>  </ROOT> 

As a reminder, execute this template with http://iisserver/Nwind/templates/template.xml .

Listing 7.8 Results of the FOR XML RAW Example
 <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">    <row OrderID="10258" EmployeeID="1" ShipName="Ernst Handel" />    <row OrderID="10270" EmployeeID="1" ShipName="Wartian Herkku" />    <row OrderID="10275" EmployeeID="1" ShipName="Magazzini Alimentari Riuniti" />    <row OrderID="10285" EmployeeID="1" ShipName="QUICK-Stop" />  </ROOT> 


XML and SQL Server 2000
XML and SQL Server 2000
ISBN: 0735711127
EAN: 2147483647
Year: 2005
Pages: 104
Authors: John Griffin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net