java.lang.Object
org.cybergarage.xml.XML

public class XMLextends Object
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 &lt;
  • > - escaped as &gt;
  • " - escaped as &quot; (when quotes are enabled)
  • ' - escaped as &apos; (when quotes are enabled)
  • Field Details

    • DEFAULT_CONTENT_TYPE

      public static final String DEFAULT_CONTENT_TYPE
      Content type applied to XML payloads sent by UPnP and SOAP responses.
      See Also:
    • DEFAULT_CONTENT_LANGUAGE

      public static final String DEFAULT_CONTENT_LANGUAGE
      Language tag applied to XML payloads when none is specified.
      See Also:
    • CHARSET_UTF8

      public static final String CHARSET_UTF8
      CHARSET_UTF8.
      See Also:
  • 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

      private static final String escapeXMLChars(String input, boolean quote)
      Escapes XML special characters in the input string.

      This method replaces the following characters with their XML entities:

      • & - always escaped as &amp;
      • < - always escaped as &lt;
      • > - always escaped as &gt;
      • ' - escaped as &apos; when quote is true
      • " - escaped as &quot; when quote is true
      Parameters:
      input - the string to escape, may be null
      quote - whether to escape quote characters (' and ")
      Returns:
      the escaped string, or null if input is null
    • escapeXMLChars

      public static final String escapeXMLChars(String input)
      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

      public static final String unescapeXMLChars(String input)
      Unescapes XML entities in the input string.

      This method replaces the following XML entities with their characters:

      • &amp; - replaced with &
      • &lt; - replaced with <
      • &gt; - replaced with >
      • &apos; - replaced with '
      • &quot; - replaced with "
      Parameters:
      input - string to unescape, may be null
      Returns:
      the unescaped string, or null if input is null