public class

XMLUtils

extends Object
java.lang.Object
   ↳ org.apache.commons.betwixt.XMLUtils

Class Overview

XMLUtils contains basic utility methods for XML.

The code for isWellFormedXMLName(String) is based on code in org.apache.xerces.util.XMLChar in Apache Xerces. The authors of this class are credited below.

Summary

Constants
String AMPERSAND_ENTITY Escaped & entity
String APOSTROPHE_ENTITY Escaped ' entity
String GREATER_THAN_ENTITY Escaped > entity
String LESS_THAN_ENTITY Escaped < entity
String QUOTE_ENTITY Escaped " entity
Public Constructors
XMLUtils()

Constructor for use by tools that required JavaBean instances.

Public Methods
final static String escapeAttributeValue(Object value)

Escape the toString of the given object.

final static String escapeBodyValue(Object value)

Escape the toString of the given object.

final static String escapeCDATAContent(String content)
Escapes the given content suitable for insertion within a CDATA sequence.
final static void escapeCDATAContent(StringBuffer bufferedContent)
Escapes the given content suitable for insertion within a CDATA sequence.
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)

Is this string a well formed xml name?

Only certain characters are allowed in well formed element and attribute names in xml.

[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String AMPERSAND_ENTITY

Escaped & entity

Constant Value: "&"

public static final String APOSTROPHE_ENTITY

Escaped ' entity

Constant Value: "'"

public static final String GREATER_THAN_ENTITY

Escaped > entity

Constant Value: ">"

public static final String LESS_THAN_ENTITY

Escaped < entity

Constant Value: "<"

public static final String QUOTE_ENTITY

Escaped " entity

Constant Value: """

Public Constructors

public XMLUtils ()

Constructor for use by tools that required JavaBean instances.

This constructor is public only to permit tools that require a JavaBean instance to operate. XMLUtils instances should not be constructed in standard programming. Instead, the class methods should be called directly.

Public Methods

public static final String escapeAttributeValue (Object value)

Escape the toString of the given object. For use in an attribute value.

Parameters
value escape value.toString()
Returns
  • text with characters restricted (for use in attributes) escaped

public static final String escapeBodyValue (Object value)

Escape the toString of the given object. For use as body text.

Parameters
value escape value.toString()
Returns
  • text with escaped delimiters

public static final String escapeCDATAContent (String content)

Escapes the given content suitable for insertion within a CDATA sequence. Within a CDATA section, only the CDEnd string ']]>' is recognized as markup.

Parameters
content the body content whose character data should be escaped in a way appropriate for use within a CDATA section of xml.
Returns
  • escaped character data, not null

public static final void escapeCDATAContent (StringBuffer bufferedContent)

Escapes the given content suitable for insertion within a CDATA sequence. Within a CDATA section, only the CDEnd string ']]>' is recognized as markup.

Parameters
bufferedContent the body content within a buffer whose character data should be escaped in a way appropriate for use within a CDATA section of xml

public static boolean isNameChar (int c)

Returns true if the specified character is a valid name character as defined by the XML 1.0 specification.

Parameters
c The character to check.
Returns
  • true if this is an XML name character

public 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.

Parameters
c The character to check.
Returns
  • trus if this is an XML name start character

public static boolean isWellFormedXMLName (String name)

Is this string 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.

Parameters
name the String to be checked for use as an xml attribute or element name. Returns false if name is null
Returns
  • true if this string would be a well-formed name