Encoding illegal XML names

SQL Anywhere uses the following rules for encoding names that are not legal XML names (for example, column names that include spaces):

XML has rules for names that differ from rules for SQL names. For example, spaces are not allowed in XML names. When a SQL name, such as a column name, is converted to an XML name, characters that are not valid characters for XML names are encoded or escaped.

For each encoded character, the encoding is based on the character's Unicode code point value, expressed as a hexadecimal number.

  • For most characters, the code point value can be represented with 16 bits or four hex digits, using the encoding _xHHHH_. These characters correspond to Unicode characters whose UTF-16 value is one 16-bit word.

  • For characters whose code point value requires more than 16 bits, eight hex digits are used in the encoding _xHHHHHHHH_. These characters correspond to Unicode characters whose UTF-16 value is two 16-bit words. However, the Unicode code point value, which is typically 5 or 6 hex digits, is used for the encoding, not the UTF-16 value.

    For example, the following query contains a column name with a space:

    SELECT EmployeeID AS "Employee ID"
    FROM Employees
    FOR XML RAW;

    and returns the following result:

    <row Employee_x0020_ID="102"/>
    <row Employee_x0020_ID="105"/>
    <row Employee_x0020_ID="129"/>
    <row Employee_x0020_ID="148"/>
    ...
  • Underscores (_) are escaped if they are followed by the character x. For example, the name Linu_x is encoded as Linu_x005F_x.

  • Colons (:) are not escaped so that namespace declarations and qualified element and attribute names can be generated using a FOR XML query.

Tip

When executing queries that contain a FOR XML clause in Interactive SQL, you may want to increase the column length by setting the truncation_length option.

 See also