Class XMLUtils

java.lang.Object
com.topologi.diffx.xml.XMLUtils

public final class XMLUtils extends Object
A utility class for XML data.
Version:
2.0, 24 March 2004
  • Constructor Details

    • XMLUtils

      private XMLUtils()
      Prevents creation of instances.
  • Method Details

    • escape

      public static String escape(String s)
      Replaces characters which are invalid in element values, by the corresponding entity in a given String.

      these characters are:

      • '&amp' by the ampersand entity "&amp"
      • '<' by the entity "&lt;"
      • Empty strings or null return respectively "" and null.

        Note: this function assumes that there are no entities in the given String. If there are existing entities, then the ampersand character will be escaped by the ampersand entity.

        This method does not replaces " (by &quot;) which is an invalid character in attribute values.

      Parameters:
      s - The String to be parsed
      Returns:
      a valid string or empty if s is null or empty.
      See Also:
    • escapeAttr

      public static String escapeAttr(String s)
      Replace characters which are invalid in attribute values, by the corresponding entity in a given String.

      these characters are:

      • '&amp' by the ampersand entity "&amp"
      • '<' by the entity "&lt;"
      • ''' by the entity "&apos;"
      • '"' by the entity "&quot;"
      • Empty strings or null return respectively "" and null.

        Note: this function assumes that there are no entities in the given String. If there are existing entities, then the ampersand character will be escaped by the ampersand entity.

      Parameters:
      s - The String to be parsed
      Returns:
      a valid string or empty if s is null or empty.
    • toElementName

      public static String toElementName(String name)
      Return a valid element name from the given string.

      Letters are put to lower case and other characters are replaced by hyphens. If the first character is not a letter it is replaced by 'x'.

      Parameters:
      name - The candidate element name
      Returns:
      A valid element name