public class

XMLUtils

extends Object
java.lang.Object
   ↳ com.microstrategy.utils.xml.XMLUtils

Class Overview

This class provides additional utilities that can be applied to the XML.

Summary

Public Constructors
XMLUtils()
Public Methods
static String compareNodes(Node base, Node other, boolean ignoreTextNodes)
This method compares two Node instances (including all their attributes and children) and returns a string with the differences between them.
static String encodeXMLAttribute(String strToEncode)
Replaces HTML unfriendly characters with their escaped equivalents.
static String escapeString(String s)
Given a String containing markup, escape the markup so it can be put into xml as normal text.
static String formatXML(String xmlIn)

This constructs a nicely formatted XML document, typically used for printing in a user readable format.

static boolean isValidGUID(String str)
Check whether the string is a valid GUID
static boolean isValidNodeKey(String str)
Check whether the string is a valid Nodekey, a loose check on whether it is consists of alphabet or digits.
static boolean isValidXML(String str)
Equivalent to parseValidateXML(String, DefaultHandler) with null for the DefaultHandler parameter.
static String loadXMLFile(String name)
Load XML from a file.
static String nodeValue(Node contextNode)
This method returns the "naive" node value of a node, that is, the concatenation of node values from all its child nodes.
static boolean parseValidateXML(String str, DefaultHandler handler)
Returns whether the given string is valid XML.
static String processElement(int level, Node objXmlElem)
ProcessElement method returns a string with tabs and newlines inserted in the appropriate spots.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public XMLUtils ()

Public Methods

public static String compareNodes (Node base, Node other, boolean ignoreTextNodes)

This method compares two Node instances (including all their attributes and children) and returns a string with the differences between them. If the nodes are equal, it returns null.

Parameters
base The base node to compare.
other The other node to compare.
ignoreTextNodes if true, this method only compare Element child nodes, that is, all text nodes are ignored.
Returns
  • A description of the nodes differences; null if equal.

public static String encodeXMLAttribute (String strToEncode)

Replaces HTML unfriendly characters with their escaped equivalents. Used to store XML string inside hidden input fields or other HTML attribute

Parameters
strToEncode the source string to encode.
Returns
  • The encoded string.

public static String escapeString (String s)

Given a String containing markup, escape the markup so it can be put into xml as normal text.

Parameters
s String to escape
Returns
  • The escaped string.

public static String formatXML (String xmlIn)

This constructs a nicely formatted XML document, typically used for printing in a user readable format.

Parameters
xmlIn The xml string to be formatted.
Returns
  • The nicely formatted XML String.
Throws
XMLSupportException Signals an error when format the XML.

public static boolean isValidGUID (String str)

Check whether the string is a valid GUID

Parameters
str string to check
Returns
  • whether the string is a valid GUID

public static boolean isValidNodeKey (String str)

Check whether the string is a valid Nodekey, a loose check on whether it is consists of alphabet or digits.

Parameters
str string to check
Returns
  • whether the string is a valid Nodekey

public static boolean isValidXML (String str)

Equivalent to parseValidateXML(String, DefaultHandler) with null for the DefaultHandler parameter.

Parameters
str string to check
Returns
  • whether the string is XML

public static String loadXMLFile (String name)

Load XML from a file.

Parameters
name The path to the file.
Returns
  • The XML string in the file.
Throws
IOException When error occurs during retrieving the XML from the file.

public static String nodeValue (Node contextNode)

This method returns the "naive" node value of a node, that is, the concatenation of node values from all its child nodes.

public static boolean parseValidateXML (String str, DefaultHandler handler)

Returns whether the given string is valid XML. The supplied parser is also used to parse the string.

Parameters
str string to check
handler handler attempt parsing with, if null, an empty DefaultHandler is used
Returns
  • whether string is XML, false if any exception occurs during parsing

public static String processElement (int level, Node objXmlElem)

ProcessElement method returns a string with tabs and newlines inserted in the appropriate spots.

Parameters
level int, level from which we want to process
objXmlElem Node, node we want to process
Returns
  • The String, with adequate format
Throws
XMLSupportException Signals an error when parsing the XML.