Package com.mirth.connect.userutil
Class XmlUtil
java.lang.Object
com.mirth.connect.userutil.XmlUtil
Provides XML utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringConverts an XML/HTML entity reference into a string with the literal character.static Stringencode(char s) Encodes a character into the corresponding XML/HTML entity.static Stringencode(char[] text, int start, int length) Converts a character array, encoding characters into the corresponding XML/HTML entities as needed.static StringConverts a string, encoding characters into the corresponding XML/HTML entities as needed.static StringprettyPrint(String input) Formats an XML string with indented markup.static StringConverts an XML string to JSON, while stripping bound namespace prefixes.static StringConverts an XML string to JSON.static StringtoJson(String xmlString, boolean autoArray, boolean autoPrimitive, boolean prettyPrint, boolean normalizeNamespaces) Converts an XML string to JSON.static StringtoJson(String xmlString, boolean autoArray, boolean autoPrimitive, boolean prettyPrint, boolean normalizeNamespaces, boolean alwaysArray, boolean alwaysExpandObjects) Converts an XML string to JSON.
-
Method Details
-
prettyPrint
Formats an XML string with indented markup.- Parameters:
input- The XML string to format.- Returns:
- The formatted XML string.
-
decode
Converts an XML/HTML entity reference into a string with the literal character.- Parameters:
entity- The XML/HTML entity to decode.- Returns:
- A string containing the decoded character.
-
encode
Encodes a character into the corresponding XML/HTML entity.- Parameters:
s- The character to encode.- Returns:
- The encoded XML/HTML entity.
-
encode
Converts a string, encoding characters into the corresponding XML/HTML entities as needed.- Parameters:
s- The string to encode.- Returns:
- The encoded string with replaced XML/HTML entities.
-
encode
Converts a character array, encoding characters into the corresponding XML/HTML entities as needed.- Parameters:
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.- Returns:
- The encoded string with replaced XML/HTML entities.
-
toJson
Converts an XML string to JSON, while stripping bound namespace prefixes.- Parameters:
xmlString- The XML string to convert.- Returns:
- The converted JSON string.
- Throws:
Exception- If conversion failed.
-
toJson
Converts an XML string to JSON.- Parameters:
xmlString- The XML string to convert.normalizeNamespaces- Whether or not to normalize namespaces by stripping prefixes.- Returns:
- The converted JSON string.
- Throws:
Exception- If conversion failed.
-
toJson
public static String toJson(String xmlString, boolean autoArray, boolean autoPrimitive, boolean prettyPrint, boolean normalizeNamespaces) throws Exception Converts an XML string to JSON.- Parameters:
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.- Returns:
- The converted JSON string.
- Throws:
Exception- If conversion failed.
-
toJson
public static String toJson(String xmlString, boolean autoArray, boolean autoPrimitive, boolean prettyPrint, boolean normalizeNamespaces, boolean alwaysArray, boolean alwaysExpandObjects) throws Exception Converts an XML string to JSON.- Parameters:
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.alwaysArray- If true, all nodes except for the top-level object will be written into JSON arrays. Overrides the autoArray option.alwaysExpandObjects- If true, all values will be written in the expanded "$" syntax.- Returns:
- The converted JSON string.
- Throws:
Exception- If conversion failed.
-