Class XMLUtils

java.lang.Object
org.apache.hadoop.hdfs.util.XMLUtils

@Private @Unstable public class XMLUtils extends Object
General xml utilities.
  • Constructor Details

    • XMLUtils

      public XMLUtils()
  • Method Details

    • mangleXmlString

      public static String mangleXmlString(String str, boolean createEntityRefs)
      Mangle a string so that it can be represented in an XML document. There are three kinds of code points in XML: - Those that can be represented normally, - Those that have to be escaped (for example, & must be represented as &) - Those that cannot be represented at all in XML. The built-in SAX functions will handle the first two types for us just fine. However, sometimes we come across a code point of the third type. In this case, we have to mangle the string in order to represent it at all. We also mangle backslash to avoid confusing a backslash in the string with part our escape sequence. The encoding used here is as follows: an illegal code point is represented as '\ABCD;', where ABCD is the hexadecimal value of the code point.
      Parameters:
      str - The input string.
      Returns:
      The mangled string.
    • unmangleXmlString

      public static String unmangleXmlString(String str, boolean decodeEntityRefs) throws XMLUtils.UnmanglingError
      Demangle a string from an XML document. See mangleXmlString(String, boolean) for a description of the mangling format.
      Parameters:
      str - The string to be demangled.
      Returns:
      The unmangled string
      Throws:
      XMLUtils.UnmanglingError - if the input is malformed.
    • addSaxString

      public static void addSaxString(ContentHandler contentHandler, String tag, String val) throws SAXException
      Add a SAX tag with a string inside.
      Parameters:
      contentHandler - the SAX content handler
      tag - the element tag to use
      val - the string to put inside the tag
      Throws:
      SAXException