| Convert a standard Java String into an XML string. It transforms
out-of-range characters (<, >, &, ", ', and non-standard
character values) into XML formatted values. Since it does correctly
escape the quote characters, this may be used for both attribute values
as well as standard text.
From
the XML recommendation:
[Definition: A parsed entity contains text, a sequence of characters,
which may represent markup or character data.]
[Definition: A character is an atomic unit of text as specified by
ISO/IEC 10646 [ISO/IEC 10646] (see also [ISO/IEC 10646-2000]).
Legal characters are tab, carriage return, line feed, and the legal
characters of Unicode and ISO/IEC 10646. The versions of these standards
cited in A.1 Normative References were current at the time this document
was prepared. New characters may be added to these standards by
amendments or new editions. Consequently, XML processors must accept
any character in the range specified for Char. The use of
"compatibility characters", as defined in section 6.8 of
[Unicode] (see also D21 in section 3.6 of [Unicode3]), is discouraged.]
Character Range
[2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] |
[#xE000-#xFFFD] | [#x10000-#x10FFFF]
// any Unicode character, excluding the surrogate blocks,
FFFE, and FFFF. //
The mechanism for encoding character code points into bit patterns may
vary from entity to entity. All XML processors must accept the UTF-8
and UTF-16 encodings of 10646; the mechanisms for signaling which of
the two is in use, or for bringing other encodings into play, are
discussed later, in 4.3.3 Character Encoding in Entities.
...
The ampersand character (&) and the left angle bracket (<)
may appear in their literal form only when used as markup delimiters, or
within a comment, a processing instruction, or a CDATA section. If they
are needed elsewhere, they must be escaped using either numeric
character references or the strings "&" and "<"
respectively. The right angle bracket (>) may be represented using the
string ">", and must, for compatibility, be escaped using
">" or a character reference when it appears in the string
"]]>" in content, when that string is not marking the end of a CDATA
section.
To allow attribute values to contain both single and double quotes, the
apostrophe or single-quote character (') may be represented as
"'", and the double-quote character (") as """.
Parameters: javaStr - the Java string to be transformed into XML text. Ifit is null, then the text "null" is appended to the Parameters: output - the StringBuffer to send the transformed XML into. |