Punctuation Character Values
If a data value contains a punctuation character that XML/HTML might interpret as a tag or other coding, XMLFOREST and XMLELEMENT convert this character to the corresponding encoded form:
ampersand (&) becomes &
apostrophe (') becomes '
quotation mark (") becomes "
open angle bracket (<) becomes <
close angle bracket (>) becomes >
To represent an apostrophe in a supplied text string, specify two apostrophes, as in the following example: 'can''t'. Doubling apostrophes is not necessary for column data.
Arguments
expression
Any valid expression. Usually the name of a column that contains the data values to be tagged. When specified as a comma-separated list, each expression in the list will be enclosed in its own XML markup tag.
AS tag
An optional argument that specifies the name of an XML markup tag. The AS keyword is mandatory if tag is specified. The case of letters in tag is preserved.
Enclosing tag with double quotes is optional. If you omit the double quotes, tag must follow XML naming standards. Enclosing tag with double quotes removes these naming restrictions.
XMLFOREST enforces XML naming standards for a valid tag name. It cannot contain any of the characters !"#$%&'()*+,/;<=>?@[\]^`{|}~, nor a space character, and cannot begin with "-", ".", or a numeric digit.
If you specify an expression without the AS tag clause, the tag value is the name of the expression column (in capital letters): <HOME_CITY>Chicago</HOME_CITY>.
Examples
The following query returns the Name column values in Sample.Person as ordinary data and as xml tagged data:
SELECT Name,XMLFOREST(Name) AS ExportName
FROM Sample.Person
A sample row of the data returned would appear as follows. Here the tag defaults to the name of the column:
Name ExportName
Emerson,Molly N. <NAME>Emerson,Molly N.</NAME>
The following example specifies multiple columns:
SELECT XMLFOREST(Home_City,
Home_State AS Home_State,
AVG(Age) AS AvAge) AS ExportData
FROM Sample.Person
The Home_City field specifies no tag; the tag is generated from the column name in all capital letters: <HOME_CITY>. The Home_State field’s AS clause is optional. It is specified here because specifying the tag name allows you to control the case of the tag: <Home_State>, rather than <HOME_STATE>. The AVG(Age) AS clause is mandatory, because the value is an aggregate, not a column value, and thus has no column name. A sample row of the data returned would appear as follows.
ExportData
<HOME_CITY>Chicago</HOME_CITY><Home_State>IL</Home_State>
<AvAge>48.0198019801980198</AvAge>
The following example returns character stream data:
SELECT XMLFOREST(name AS Para,Notes AS Para) AS XMLJobHistory
FROM Sample.Employee
A sample row of the data returned would appear as follows:
XMLJobHistory
<Para>Emerson,Molly N.</Para><Para><![CDATA[Molly worked at DynaMatix Holdings Inc. as a Marketing Manager]]></Para>
The following example shows XMLFOREST functions using a subquery value:
SELECT XMLFOREST(Name,DOB,Age,
(SELECT XMLFOREST(Name,DOB) FROM Sample.Person WHERE %ID=2) AS ExportName)
FROM Sample.Person where %ID=1
A sample row of the data returned would appear as follows:
<NAME>Zahn,Rob F.</NAME><DOB>38405</DOB><AGE>71</AGE><ExportName><NAME>Quinn,Mark N.</NAME><DOB>30999</DOB></ExportName>