SQL Anywhere supports two different ways to obtain query results from your relational data as XML:
FOR XML clause The FOR XML clause can be used in a SELECT statement to generate an XML document.
For information about using the FOR XML clause, see Using the FOR XML clause to retrieve query results as XML and SELECT statement.
SQL/XML SQL Anywhere supports functions based on the draft SQL/XML standard that generate XML documents from relational data.
For information about using one or more of these functions in a query, see Using SQL/XML to obtain query results as XML.
The FOR XML clause and the SQL/XML functions supported by SQL Anywhere give you two alternatives for generating XML from your relational data. You can usually use one or the other to generate the same XML.
For example, this query uses FOR XML AUTO to generate XML:
SELECT ID, Name FROM Products WHERE Color='black' FOR XML AUTO; |
The following query uses the XMLELEMENT function to generate XML:
SELECT XMLELEMENT(NAME product, XMLATTRIBUTES(ID, Name)) FROM Products WHERE Color='black'; |
Both queries generate the following XML (the result set has been formatted to make it easier to read):
<product ID="302" Name="Tee Shirt"/> <product ID="400" Name="Baseball Cap"/> <product ID="501" Name="Visor"/> <product ID="700" Name="Shorts"/> |
Using the FOR XML clause to retrieve query results as XML
Using FOR XML RAW
Using FOR XML AUTO
Using FOR XML EXPLICIT
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |