Package org.apache.hadoop.hdfs.util
Class XMLUtils
java.lang.Object
org.apache.hadoop.hdfs.util.XMLUtils
General xml utilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException that reflects an invalid XML document.static classRepresents a bag of key-value pairs encountered during parsing an XML file.static classException that reflects a string that cannot be unmangled. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSaxString(ContentHandler contentHandler, String tag, String val) Add a SAX tag with a string inside.static StringmangleXmlString(String str, boolean createEntityRefs) Mangle a string so that it can be represented in an XML document.static StringunmangleXmlString(String str, boolean decodeEntityRefs) Demangle a string from an XML document.
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
mangleXmlString
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. SeemangleXmlString(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 handlertag- the element tag to useval- the string to put inside the tag- Throws:
SAXException
-