public class XMLUtils extends Object
Contains basic utility methods for XML.
Parts of this class are borrowed from Apache Commons Betwixt whose class in turn is based on code in Apache Xerces.The code for isWellFormedXMLName(java.lang.String) is based on code in
org.apache.xerces.util.XMLChar
in Apache Xerces.
The authors of the Xerces and Betwixt classes are credited below.
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_ATTRIBUTE_LENGTH
Maximum length of attribute values that we want to generate.
|
static int |
MAX_NAME_LENGTH
Maximum length of a tag or attribute name that we want to generate.
|
| Constructor and Description |
|---|
XMLUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
base64Encode(String value)
Encodes the given value with Base64.
|
static List |
findCDataCutPoints(String text)
Determines whether the given string contains special characters that cannot
be used in XML, and if not, finds the cut points where to split the text
when writing it in a CDATA section.
|
static boolean |
hasIllegalXMLCharacters(String text)
Determines whether the given string contains special characters that cannot
be used in XML.
|
static boolean |
isNameChar(int c)
Returns true if the specified character is a valid name character as defined by the XML 1.0 specification.
|
static boolean |
isNameStartChar(int c)
Returns true if the specified character is a valid name start character as defined in the XML 1.0 specification.
|
static boolean |
isWellFormedXMLName(String name)
Determines whether the given string is a well formed xml name.
|
public static final int MAX_ATTRIBUTE_LENGTH
public static final int MAX_NAME_LENGTH
public static boolean isWellFormedXMLName(String name)
Determines whether the given string is a well formed xml name. Only certain characters are allowed in well formed element and attribute names in xml. For example, white space is not allowed in a name.
The code for this method is based on code in org.apache.xerces.util.XMLChar
in Apache Xerces.
The authors of this class are credited at the top of this class.
name - The string to be checked for use as an xml attribute or element name.
Returns false if name is nullpublic static boolean isNameChar(int c)
c - The character to checkpublic static boolean isNameStartChar(int c)
c - The character to checkpublic static boolean hasIllegalXMLCharacters(String text)
text - The texttrue if the text contains special characterspublic static String base64Encode(String value)
value - The value to encodepublic static List findCDataCutPoints(String text)
text - The textnull if the text contains special characters, or the list of cut points otherwiseCopyright © 2010-2015 Pivotal Software, Inc. All rights reserved.