public abstract class

DOMSupport

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

Class Overview

The DOMSupport class is used to abstract away parser-specific and JAXP-supported DOM-related operations. It can be used to parse XML, serialize DOM trees, execute XPath calls, and create new DOM Documents.

Summary

Public Constructors
DOMSupport()
Public Methods
abstract Node getChild(Node contextNode, String nodeName)
Returns the child node of the given node with the given node name.
abstract NodeList getChildren(Node contextNode, String nodeName)
Returns a list of children of the context node with the given node name.
abstract Node getDescendent(Node contextNode, String reducedXPath)
This method executes the given reduced XPath expression, and returns the first node which fits the expression.
abstract NodeList getDescendents(Node contextNode, String reducedXPath)
This method executes the given reduced XPath expression, and returns a list of nodes which fit the expression.
abstract Document newDocument()
Returns a new DOM Document, with no elements in it.
static DOMSupport newInstance()
The newInstance method can be used to obtain an instance of a DOMSupport object.
abstract Document parse(InputStream stream)
Parses the given InputStream's into a DOM Document, without DTD validation.
abstract Document parse(File f, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware, EntityResolver entityResolver)
Parses the given XML File's contents into a DOM Document, with or without DTD validation, with or without namespace awareness.
abstract Document parse(String xmlString, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware, EntityResolver entityResolver)
Parses the given XML String into a DOM Document, with or without DTD validation.
abstract Document parse(File f, boolean isValidating, ErrorHandler errorHandler)
Parses the given XML File's contents into a DOM Document, with or without DTD validation.
abstract Document parse(File f, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware)
Parses the given XML File's contents into a DOM Document, with or without DTD validation, with or with namespace awareness.
abstract Document parse(InputStream stream, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware, EntityResolver entityResolver)
Parses the given InputStream's into a DOM Document, with or without DTD validation.
abstract Document parse(String xmlString, boolean isValidating, ErrorHandler errorHandler)
Parses the given XML String into a DOM Document, with or without DTD validation.
abstract Document parse(String xmlString, boolean isValidating)
Parses the given XML String into a DOM Document, with or without DTD validation.
abstract Document parse(InputStream stream, ParserParameters parameters)
Parses the given InputStream's contents into a DOM Document based on the given parameters.
abstract Document parse(String xmlString)
Parses the given XML String into a DOM Document, without DTD validation.
abstract Document parse(String xmlString, ParserParameters parameters)
Parses the given XML String into a DOM Document based on the given parameters.
abstract Document parse(InputStream stream, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware)
Parses the given InputStream's into a DOM Document, with or without DTD validation.
abstract Document parse(InputStream stream, boolean isValidating)
Parses the given InputStream's into a DOM Document, with or without DTD validation.
abstract Document parse(File f, ParserParameters parameters)
Parses the given XML File's contents into a DOM Document based on the given parameters.
abstract Document parse(String xmlString, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware)
Parses the given XML String into a DOM Document, with or without DTD validation.
abstract Document parse(File f, boolean isValidating)
Parses the given XML File's contents into a DOM Document, with or without DTD validation.
abstract Document parse(File f)
Parses the given XML File's contents into a DOM Document, without DTD validation.
abstract Document parse(InputStream stream, boolean isValidating, ErrorHandler errorHandler)
Parses the given InputStream's into a DOM Document, with or without DTD validation.
abstract String serialize(Node n, boolean indent)
abstract String serialize(Node n, SerializerParameters parameters)
Serializes the given node and its children into an XML String.
abstract String serialize(Node n)
Serializes the given node and its children into an XML String.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public DOMSupport ()

Public Methods

public abstract Node getChild (Node contextNode, String nodeName)

Returns the child node of the given node with the given node name. This uses DOM traversal, and as such it should be significantly faster than selectSingleNode.

Parameters
contextNode The node whose child will be traversed to.
nodeName The name of the child node
Returns
  • The first node with the given node name, or null if none exists.

public abstract NodeList getChildren (Node contextNode, String nodeName)

Returns a list of children of the context node with the given node name.

Parameters
contextNode The node to search from.
nodeName The name of the child nodes to return.
Returns
  • A NodeList containing those nodes which are children of the context node with the given node name.

public abstract Node getDescendent (Node contextNode, String reducedXPath)

This method executes the given reduced XPath expression, and returns the first node which fits the expression. This method does not support conditions or recursive traversal of the tree. Note that this method uses DOM traversal to implement this functionality.

Parameters
contextNode The context node for the reduced XPath expression.
reducedXPath The reduced XPath expression to execute.
Returns
  • A Node containing the first node found that fits the condition.
Throws
IllegalArgumentException Thrown if the reduced XPath expression is invalid.

public abstract NodeList getDescendents (Node contextNode, String reducedXPath)

This method executes the given reduced XPath expression, and returns a list of nodes which fit the expression. This method does not support conditions or recursive traversal of the tree. Note that this method uses DOM traversal to implement this functionality.

A reduced XPath expression only supports parts of the XPath specification, in particular:

  • Traversal to elements, attributes, or text nodes
  • / at beginning of path to start at root of document and ./ to start at current node
It does not support recursive statements("//") or conditional statements.

Parameters
contextNode The context node for the reduced XPath expression.
reducedXPath The reduced XPath expression to execute.
Returns
  • A NodeList containing the nodes fitting the condition.
Throws
IllegalArgumentException Thrown if the reduced XPath expression is invalid.

public abstract Document newDocument ()

Returns a new DOM Document, with no elements in it.

Returns
  • A new DOM Document.
Throws
XMLSupportRuntimeException Signals an error when creating the new document. This generally signals a configuration error in the XML parser/XSL processor libraries.

public static DOMSupport newInstance ()

The newInstance method can be used to obtain an instance of a DOMSupport object. This instance can then be used to call any of the methods on this object.

Returns
  • A DOMSupport instance.

public abstract Document parse (InputStream stream)

Parses the given InputStream's into a DOM Document, without DTD validation.

Parameters
stream The input stream representing the xml to parse.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (File f, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware, EntityResolver entityResolver)

Parses the given XML File's contents into a DOM Document, with or without DTD validation, with or without namespace awareness.

Parameters
f The file to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
namespaceAware Whether the DocumentBuilderFactory is initialized with a specific namespace awareness.
entityResolver The org.xml.sax.EntityResolver to be used to resolve entity references.
Returns
  • A DOM Document representing the XML in the file.
Throws
XMLSupportException Signals an error when parsing the XML or accessing the file.

public abstract Document parse (String xmlString, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware, EntityResolver entityResolver)

Parses the given XML String into a DOM Document, with or without DTD validation.

Parameters
xmlString The XML String to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
namespaceAware Whether the DocumentBuilderFactory is initialized with a specific namespace awareness.
entityResolver The org.xml.sax.EntityResolver to be used to resolve entity references.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (File f, boolean isValidating, ErrorHandler errorHandler)

Parses the given XML File's contents into a DOM Document, with or without DTD validation.

Parameters
f The file to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
Returns
  • A DOM Document representing the XML in the file.
Throws
XMLSupportException Signals an error when parsing the XML or accessing the file.

public abstract Document parse (File f, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware)

Parses the given XML File's contents into a DOM Document, with or without DTD validation, with or with namespace awareness.

Parameters
f The file to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
namespaceAware Whether the DocumentBuilderFactory is initialized with a specific namespace awareness.
Returns
  • A DOM Document representing the XML in the file.
Throws
XMLSupportException Signals an error when parsing the XML or accessing the file.

public abstract Document parse (InputStream stream, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware, EntityResolver entityResolver)

Parses the given InputStream's into a DOM Document, with or without DTD validation.

Parameters
stream The input stream representing the xml to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
namespaceAware Whether the DocumentBuilderFactory is initialized with a specific namespace awareness.
entityResolver The org.xml.sax.EntityResolver to be used to resolve entity references.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (String xmlString, boolean isValidating, ErrorHandler errorHandler)

Parses the given XML String into a DOM Document, with or without DTD validation.

Parameters
xmlString The XML String to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (String xmlString, boolean isValidating)

Parses the given XML String into a DOM Document, with or without DTD validation. If with DTD validation, the error will be handled by default error handler.

Parameters
xmlString The XML String to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (InputStream stream, ParserParameters parameters)

Parses the given InputStream's contents into a DOM Document based on the given parameters.

Parameters
stream The input stream representing the xml to parse.
parameters a ParserParameters class with the parameter values.

public abstract Document parse (String xmlString)

Parses the given XML String into a DOM Document, without DTD validation.

Parameters
xmlString The XML String to parse.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (String xmlString, ParserParameters parameters)

Parses the given XML String into a DOM Document based on the given parameters.

Parameters
xmlString The XML String to parse.
parameters a ParserParameters class with the parameter values.

public abstract Document parse (InputStream stream, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware)

Parses the given InputStream's into a DOM Document, with or without DTD validation.

Parameters
stream The input stream representing the xml to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
namespaceAware Whether the DocumentBuilderFactory is initialized with a specific namespace awareness.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (InputStream stream, boolean isValidating)

Parses the given InputStream's into a DOM Document, with or without DTD validation. If with DTD validation, the error will be handled by default error handler.

Parameters
stream The input stream representing the xml to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (File f, ParserParameters parameters)

Parses the given XML File's contents into a DOM Document based on the given parameters.

Parameters
f The file to parse.
parameters a ParserParameters class with the parameter values.

public abstract Document parse (String xmlString, boolean isValidating, ErrorHandler errorHandler, boolean namespaceAware)

Parses the given XML String into a DOM Document, with or without DTD validation.

Parameters
xmlString The XML String to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
namespaceAware Whether the DocumentBuilderFactory is initialized with a specific namespace awareness.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract Document parse (File f, boolean isValidating)

Parses the given XML File's contents into a DOM Document, with or without DTD validation. If with DTD validation, the error will be handled by default error handler.

Parameters
f The file to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise
Returns
  • A DOM Document representing the XML in the file.
Throws
XMLSupportException Signals an error when parsing the XML or accessing the file.

public abstract Document parse (File f)

Parses the given XML File's contents into a DOM Document, without DTD validation.

Parameters
f The file to parse.
Returns
  • A DOM Document representing the XML in the file.
Throws
XMLSupportException Signals an error when parsing the XML or accessing the file.

public abstract Document parse (InputStream stream, boolean isValidating, ErrorHandler errorHandler)

Parses the given InputStream's into a DOM Document, with or without DTD validation.

Parameters
stream The input stream representing the xml to parse.
isValidating true if the parser produced will validate documents as they are parsed; false otherwise.
errorHandler The org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.
Returns
  • A DOM Document representing the XML string.
Throws
XMLSupportException Signals an error when parsing the XML.

public abstract String serialize (Node n, boolean indent)

public abstract String serialize (Node n, SerializerParameters parameters)

Serializes the given node and its children into an XML String.

Parameters
n An XML Node, which will be serialized into an XML String.
parameters a SerializerParameters class with the parameter values.
Returns
  • A String representing the given XML tree fragment.

public abstract String serialize (Node n)

Serializes the given node and its children into an XML String.

Parameters
n An XML Node, which will be serialized into an XML String.
Returns
  • A String representing the given XML tree fragment.