mls.common
Class XmlObject

java.lang.Object
  |
  +--mls.common.XmlObject
Direct Known Subclasses:
TranslatingXmlObject, Viewer

public class XmlObject
extends java.lang.Object

Methods to parse and access XML documents


Field Summary
protected static java.lang.String[] INDENT
          Used in XML string creation and printing
 
Constructor Summary
XmlObject()
           
 
Method Summary
static java.lang.String dump(org.w3c.dom.Document xml)
          Dump the specified XML document to a string
private static java.lang.String dumpElement(org.w3c.dom.Element el, int indent)
          Dump a single element at the specified indent level
private static java.util.Vector getChildren(org.w3c.dom.Document parent, java.lang.String elTagName)
          Return child elements of a document with specified tag name
private static java.util.Vector getChildren(org.w3c.dom.Element parent, java.lang.String elTagName)
          Return child elements of an element with specified tag name
protected static org.w3c.dom.Element getElement(org.w3c.dom.Document doc, java.lang.String elTagName)
          Return the first element matching the elTagName in a document
protected static org.w3c.dom.Element getElement(org.w3c.dom.Element parent, java.lang.String elTagName)
          Return the first element matching the elTagName in an element
protected static org.w3c.dom.Element getElement(org.w3c.dom.Element parent, java.lang.String elTagName, int n)
          Return the nth element matching the elTagName in an element
protected static java.lang.String getElementText(org.w3c.dom.Element el)
          Return the specified element's text
private static org.apache.xerces.parsers.DOMParser getParser()
          Common routine to get a DOM parser
protected static java.lang.String indent(int level)
          Return an indentation string based on level
private static java.util.Vector narrow(org.w3c.dom.NodeList descendents, org.w3c.dom.Node parent)
          Narrow descendents node list to the child elements
protected static int nElements(org.w3c.dom.Element element, java.lang.String elTagName)
          Return a count of all elements under element matching the tag
protected static org.w3c.dom.Document parse(java.lang.String fileName)
          Create a DOM document structure from the specified XML file
protected static org.w3c.dom.Document parseString(java.lang.String s)
          Create a DOM document structure from the specified XML string
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

INDENT

protected static final java.lang.String[] INDENT
Used in XML string creation and printing
Constructor Detail

XmlObject

public XmlObject()
Method Detail

indent

protected static java.lang.String indent(int level)
Return an indentation string based on level
Parameters:
level - the level of indentation
Returns:
a string of spaces based on level

parseString

protected static org.w3c.dom.Document parseString(java.lang.String s)
Create a DOM document structure from the specified XML string
Parameters:
s - The string containing XML document
Returns:
A DOM Document or null if an error occurs

parse

protected static org.w3c.dom.Document parse(java.lang.String fileName)
Create a DOM document structure from the specified XML file
Parameters:
fileName - The name of the XML document
Returns:
A DOM Document or null if an error occurs

getParser

private static org.apache.xerces.parsers.DOMParser getParser()
                                                      throws org.xml.sax.SAXNotSupportedException,
                                                             org.xml.sax.SAXNotRecognizedException
Common routine to get a DOM parser
Returns:
a DOM parser with external entity inclusion enabled

getElement

protected static org.w3c.dom.Element getElement(org.w3c.dom.Element parent,
                                                java.lang.String elTagName)
Return the first element matching the elTagName in an element
Parameters:
parent - the parent element to search under
elTagName - the element tag to look for
Returns:
a DOM element or null if not found

getElement

protected static org.w3c.dom.Element getElement(org.w3c.dom.Document doc,
                                                java.lang.String elTagName)
Return the first element matching the elTagName in a document
Parameters:
doc - the DOM document to search
elTagName - the element tag to look for
Returns:
a DOM element

getElement

protected static org.w3c.dom.Element getElement(org.w3c.dom.Element parent,
                                                java.lang.String elTagName,
                                                int n)
Return the nth element matching the elTagName in an element
Parameters:
parent - the parent element to search under
elTagName - the element tag to look for
n - the number of the element to return
Returns:
a DOM element

nElements

protected static int nElements(org.w3c.dom.Element element,
                               java.lang.String elTagName)
Return a count of all elements under element matching the tag
Parameters:
element - the parent element to search under
elTagName - the element tag to look for
Returns:
the number of matching elements

getChildren

private static java.util.Vector getChildren(org.w3c.dom.Element parent,
                                            java.lang.String elTagName)
Return child elements of an element with specified tag name
Parameters:
parent - the parent element to search under
elTagName - the element tag to look for
Returns:
a vector of matching elements (empty if none found)

getChildren

private static java.util.Vector getChildren(org.w3c.dom.Document parent,
                                            java.lang.String elTagName)
Return child elements of a document with specified tag name
Parameters:
parent - the parent document to search under
elTagName - the element tag to look for
Returns:
a vector of matching elements (empty if none found)

narrow

private static java.util.Vector narrow(org.w3c.dom.NodeList descendents,
                                       org.w3c.dom.Node parent)
Narrow descendents node list to the child elements
Parameters:
descendents - the descdendent list to narrow
parent - the parent node to match on
Returns:
a vector of child elements (empty if none found)

getElementText

protected static java.lang.String getElementText(org.w3c.dom.Element el)
Return the specified element's text
Parameters:
element - the element to examine
Returns:
the text for the specified element

dump

public static java.lang.String dump(org.w3c.dom.Document xml)
Dump the specified XML document to a string
Parameters:
xml - the document to dump
Returns:
a string containing the XML structure

dumpElement

private static java.lang.String dumpElement(org.w3c.dom.Element el,
                                            int indent)
Dump a single element at the specified indent level
Parameters:
el - the element to dump
indent - the indentation level of this element
Returns:
a string containing the XML structure