java.lang.Object
org.cybergarage.xml.XML
Utility class for XML character escaping and unescaping operations.
This class provides static methods to escape and unescape XML special characters to ensure valid XML output and proper parsing of XML content.
The following characters are handled:
- & - escaped as &
- < - escaped as <
- > - escaped as >
- " - escaped as " (when quotes are enabled)
- ' - escaped as ' (when quotes are enabled)
Field Summary
Constructor Summary
ConstructorsConstructorDescriptionXML()The escape and encode helpers below and the content-type constants are all static, so an instance carries nothing.Method Summary
Modifier and TypeMethodDescriptionstatic final StringescapeXMLChars(String input) Escapes XML special characters in the input string, including quotes.private static final StringescapeXMLChars(String input, boolean quote) Escapes XML special characters in the input string.static final StringunescapeXMLChars(String input) Unescapes XML entities in the input string.
Field Details
DEFAULT_CONTENT_TYPE
Content type applied to XML payloads sent by UPnP and SOAP responses.- See Also:
DEFAULT_CONTENT_LANGUAGE
Language tag applied to XML payloads when none is specified.- See Also:
CHARSET_UTF8
Constructor Details
XML
public XML()The escape and encode helpers below and the content-type constants are all static, so an instance carries nothing.
Method Details
escapeXMLChars
Escapes XML special characters in the input string.This method replaces the following characters with their XML entities:
- & - always escaped as &
- < - always escaped as <
- > - always escaped as >
- ' - escaped as ' when quote is true
- " - escaped as " when quote is true
- Parameters:
input- the string to escape, may be nullquote- whether to escape quote characters (' and ")- Returns:
- the escaped string, or null if input is null
escapeXMLChars
Escapes XML special characters in the input string, including quotes.This is a convenience method that calls
escapeXMLChars(String, boolean)with quote set to true.- Parameters:
input- the string to escape, may be null- Returns:
- the escaped string, or null if input is null
unescapeXMLChars
Unescapes XML entities in the input string.This method replaces the following XML entities with their characters:
- & - replaced with &
- < - replaced with <
- > - replaced with >
- ' - replaced with '
- " - replaced with "
- Parameters:
input- string to unescape, may be null- Returns:
- the unescaped string, or null if input is null