public class XmlUtil extends Object
Modifier and Type | Method and Description |
---|---|
static String |
decode(String entity)
Converts an XML/HTML entity reference into a string with the literal character.
|
static String |
encode(char s)
Encodes a character into the corresponding XML/HTML entity.
|
static String |
encode(char[] text,
int start,
int length)
Converts a character array, encoding characters into the corresponding XML/HTML entities as
needed.
|
static String |
encode(String s)
Converts a string, encoding characters into the corresponding XML/HTML entities as needed.
|
static String |
prettyPrint(String input)
Formats an XML string with indented markup.
|
static String |
toJson(String xmlString)
Converts an XML string to JSON, while stripping bound namespace prefixes.
|
static String |
toJson(String xmlString,
boolean normalizeNamespaces)
Converts an XML string to JSON.
|
static String |
toJson(String xmlString,
boolean autoArray,
boolean autoPrimitive,
boolean prettyPrint,
boolean normalizeNamespaces)
Converts an XML string to JSON.
|
public static String prettyPrint(String input)
input
- The XML string to format.public static String decode(String entity)
entity
- The XML/HTML entity to decode.public static String encode(char s)
s
- The character to encode.public static String encode(String s)
s
- The string to encode.public static String encode(char[] text, int start, int length)
text
- The character array to encode.start
- The index to start at in the character array.length
- The maximum amount of characters to read from the array.public static String toJson(String xmlString) throws Exception
xmlString
- The XML string to convert.Exception
- If conversion failed.public static String toJson(String xmlString, boolean normalizeNamespaces) throws Exception
xmlString
- The XML string to convert.normalizeNamespaces
- Whether or not to normalize namespaces by stripping prefixes.Exception
- If conversion failed.public static String toJson(String xmlString, boolean autoArray, boolean autoPrimitive, boolean prettyPrint, boolean normalizeNamespaces) throws Exception
xmlString
- The XML string to convert.autoArray
- If true, sibling nodes with the same tag name will be consolidated into a JSON
array. If false, multiple properties with the same name will be present.autoPrimitive
- If true, element text will be converted to JSON primitive values where applicable.
If false, element text will always be converted to string values.prettyPrint
- Whether or not to fully indent the JSON output.normalizeNamespaces
- Whether or not to normalize namespaces by stripping prefixes.Exception
- If conversion failed.