de.zeigermann.xml
Class XMLEncode

java.lang.Object
  |
  +--de.zeigermann.xml.XMLEncode

public final class XMLEncode
extends Object

Collection of XML encoding/decoding helpers.
This is all about the special characters & and <, and for attributes " and '. These must be encoded/decoded from/to XML.

Author:
Olli Z.

Constructor Summary
XMLEncode()
           
 
Method Summary
static boolean isCompatibleWithCDATABlock(String text)
          Can this text be stored into a CDATA block?
static boolean isWhiteSpace(String text)
          Checks if this text purely consists of the white space characters ' ', TAB, NEWLINE.
static boolean needsEncoding(String text)
          Checks if this text needs encoding in order to be represented in XML.
static boolean needsEncoding(String data, boolean checkForAttr)
          Checks if this text needs encoding in order to be represented in XML.
static String xmlDecodeTextToCDATA(String pcdata)
          Make CDATA out of possibly encoded PCDATA.
static String xmlEncodeText(String text)
          Encodes text as XML in the most suitable way, either CDATA block or PCDATA.
static String xmlEncodeTextAsCDATABlock(String text)
          Returns string as CDATA block if possible, otherwise null.
static String xmlEncodeTextAsPCDATA(String text)
          Encodes any text as PCDATA.
static String xmlEncodeTextAsPCDATA(String text, boolean forAttribute)
          Encodes any text as PCDATA.
static String xmlEncodeTextAsPCDATA(String text, boolean forAttribute, char quoteChar)
          Encodes any text as PCDATA.
static String xmlEncodeTextForAttribute(String text, char quoteChar)
          Makes any text fit into XML attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLEncode

public XMLEncode()
Method Detail

isWhiteSpace

public static final boolean isWhiteSpace(String text)
Checks if this text purely consists of the white space characters ' ', TAB, NEWLINE.


xmlEncodeTextForAttribute

public static final String xmlEncodeTextForAttribute(String text,
                                                     char quoteChar)
Makes any text fit into XML attributes.


xmlEncodeText

public static final String xmlEncodeText(String text)
Encodes text as XML in the most suitable way, either CDATA block or PCDATA.


xmlEncodeTextAsPCDATA

public static final String xmlEncodeTextAsPCDATA(String text)
Encodes any text as PCDATA.


xmlEncodeTextAsPCDATA

public static final String xmlEncodeTextAsPCDATA(String text,
                                                 boolean forAttribute)
Encodes any text as PCDATA.

Parameters:
forAttribute - if you want quotes and apostrophes specially treated for attributes

xmlEncodeTextAsPCDATA

public static final String xmlEncodeTextAsPCDATA(String text,
                                                 boolean forAttribute,
                                                 char quoteChar)
Encodes any text as PCDATA.

Parameters:
forAttribute - if you want quotes and apostrophes specially treated for attributes
quoteChar - if this is for attributes this char is used to quote the attribute value

xmlEncodeTextAsCDATABlock

public static final String xmlEncodeTextAsCDATABlock(String text)
Returns string as CDATA block if possible, otherwise null.


needsEncoding

public static final boolean needsEncoding(String text)
Checks if this text needs encoding in order to be represented in XML.


needsEncoding

public static final boolean needsEncoding(String data,
                                          boolean checkForAttr)
Checks if this text needs encoding in order to be represented in XML. Set checkForAttr if you want to check for storability in an attribute.


isCompatibleWithCDATABlock

public static final boolean isCompatibleWithCDATABlock(String text)
Can this text be stored into a CDATA block?


xmlDecodeTextToCDATA

public static final String xmlDecodeTextToCDATA(String pcdata)
Make CDATA out of possibly encoded PCDATA.
E.g. make '&' out of '&amp;'



Copyright 2002-2003 Oliver Zeigermann. All Rights Reserved.