net.sourceforge.groboutils.util.xml.v1
Class XMLUtil

java.lang.Object
  extended bynet.sourceforge.groboutils.util.xml.v1.XMLUtil

public class XMLUtil
extends java.lang.Object

A Utility to aid in various XML activities.

Since:
May 21, 2001
Version:
$Date: 2003/02/10 22:52:50 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Field Summary
protected static XMLUtil s_instance
           
 
Constructor Summary
protected XMLUtil()
           
 
Method Summary
static XMLUtil getInstance()
           
 java.lang.String utf2xml(java.lang.String javaStr)
          Convert a standard Java String into an XML string.
 void utf2xml(java.lang.String javaStr, java.lang.StringBuffer output)
          Convert a standard Java String into an XML string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_instance

protected static XMLUtil s_instance
Constructor Detail

XMLUtil

protected XMLUtil()
Method Detail

getInstance

public static XMLUtil getInstance()

utf2xml

public java.lang.String utf2xml(java.lang.String javaStr)
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.

Parameters:
javaStr - the Java string to be transformed into XML text. If the string is null, then null is returned.
Returns:
the XML version of javaStr.
See Also:
utf2xml( String, StringBuffer )

utf2xml

public void utf2xml(java.lang.String javaStr,
                    java.lang.StringBuffer output)
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 "&amp;" and "&lt;"
 respectively. The right angle bracket (>) may be represented using the
 string "&gt;", and must, for compatibility, be escaped using
 "&gt;" 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
 "&apos;", and the double-quote character (") as "&quot;".
 

Parameters:
javaStr - the Java string to be transformed into XML text. If it is null, then the text "null" is appended to the
output - the StringBuffer to send the transformed XML into.


Copyright © 2001-2003 by The GroboUtils Project