Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.muse.util.xml
Class XmlUtils

    java.lang.Object
      org.apache.muse.util.xml.XmlUtils

public class XmlUtils
extends java.lang.Object

XmlUtils is a collection of utility methods related to XML parsing and manipulation. It is mostly based on JAXP, but some of the methods require additional features that are only found in Apache Xerces.

Author:
  Dan Jemiolo (danj)

Field Summary
`static org.w3c.dom.Document` | `EMPTY_DOC` An empty Document that can be used as a DOM factory for creation of random XML fragments.
`static java.lang.String` | `TARGET_NS` The targetNamespace attribute name.
`static java.lang.String` | `XML_HEADER` The standard XML document header - does not include encoding.
`static java.lang.String` | `XMLNS_PREFIX` Standard prefix for XML namespace attributes.

Constructor Summary
`XmlUtils()`

Method Summary
`static org.w3c.dom.Node[]` | `convertToArray(org.w3c.dom.NodeList list)`
`static org.w3c.dom.Node` | `convertToNode(org.w3c.dom.Document document, java.lang.Object value)` Converts an object into its XML representation; this usually means that the object's toString() method is called and the result used to create a DOM Text object.
`static org.w3c.dom.Document` | `createDocument()`
`static org.w3c.dom.Document` | `createDocument(java.io.File file)`
`static org.w3c.dom.Document` | `createDocument(org.xml.sax.InputSource source)`
`static org.w3c.dom.Document` | `createDocument(java.io.InputStream stream)`
`static org.w3c.dom.Document` | `createDocument(java.lang.String xml)`
`static org.w3c.dom.Document` | `createDocument(java.net.URI uri)` This is a convenience method that converts the given URI to a File and invokes createDocument(File).
`static org.w3c.dom.Element` | `createElement(org.w3c.dom.Document doc, QName qname)`
`static org.w3c.dom.Element` | `createElement(org.w3c.dom.Document doc, QName qname, org.w3c.dom.Node value, boolean embedChildren)`
`static org.w3c.dom.Element` | `createElement(org.w3c.dom.Document doc, QName qname, java.lang.Object value)`
`static org.w3c.dom.Element` | `createElement(QName qname)` This is a convenience method that creates a new, empty Element; the owner of the Element is EMPTY_DOC.
`static org.w3c.dom.Element` | `createElement(QName qname, java.lang.Object value)` This is a convenience method that creates a new Element with the given value; the owner of the Element is EMPTY_DOC.
`static boolean` | `equals(org.w3c.dom.Element e1, org.w3c.dom.Element e2)`
`static java.lang.String` | `extractText(org.w3c.dom.Element element)`
`static org.w3c.dom.Element` | `findFirstInSubTree(org.w3c.dom.Element context, QName qname)` This is a convenience method that returns the first Element in the array returned by findInSubTree(Element, QName), if any.
`static org.w3c.dom.Element[]` | `findInSubTree(org.w3c.dom.Element context, QName qname)` Searches through an entire sub-tree for child Elements whose QName matches the one given.
`static org.w3c.dom.Element[]` | `getAllElements(org.w3c.dom.Node context)`
`static org.w3c.dom.Element[]` | `getAllElements(org.w3c.dom.Node context, java.lang.String namespace)`
`static org.w3c.dom.Element[]` | `getAllElements(org.w3c.dom.Node context, java.lang.String namespace, java.lang.String localName)`
`static java.util.Map` | `getAllNamespaces(org.w3c.dom.Element xml)` Searches the given sub-tree and returns all of the namespace URIs that are used to declare the root Element and its child Elements.
`static java.lang.String` | `getAttribute(org.w3c.dom.Element xml, QName qname)`
`static java.lang.Boolean` | `getBoolean(org.w3c.dom.Element xml)`
`static java.util.Date` | `getDate(org.w3c.dom.Element xml)`
`static org.w3c.dom.Element` | `getDocumentRoot(org.w3c.dom.Node xml)`
`static java.lang.Double` | `getDouble(org.w3c.dom.Element xml)`
`static org.w3c.dom.Element` | `getElement(org.w3c.dom.Node context, QName qname)` This is a convenience method that returns the zeroth child Element under the given Node.
`static org.w3c.dom.Element` | `getElement(org.w3c.dom.Node context, QName qname, int index)`
`static QName` | `getElementQName(org.w3c.dom.Element xml)`
`static org.w3c.dom.Element[]` | `getElements(org.w3c.dom.Node context, QName qname)`
`static java.lang.String[]` | `getElementsText(org.w3c.dom.Node context, QName qname)` Searches a sub-tree for all direct child Elements with the given Qname and returns the text content of those Elements, if any.
`static java.lang.String` | `getElementText(org.w3c.dom.Node context, QName qname)` Searches a sub-tree for an Element with the given QName, and then returns its text content, if any.
`static org.w3c.dom.Element` | `getFirstElement(org.w3c.dom.Node context)`
`static java.lang.Float` | `getFloat(org.w3c.dom.Element xml)`
`static int` | `getHashCode(org.w3c.dom.Element xml)`
`static java.lang.Integer` | `getInteger(org.w3c.dom.Element xml)`
`static java.lang.Long` | `getLong(org.w3c.dom.Element xml)`
`static QName` | `getQName(org.w3c.dom.Element xml)` Retrieves the text from the element specified and parses it into a fully-resolved QName.
`static QName` | `getQNameFromChild(org.w3c.dom.Element xml, QName childQName)` Retrieves the text from the child element specified and parses it into a fully-resolved QName.
`static java.lang.Short` | `getShort(org.w3c.dom.Element xml)`
`static boolean` | `haveMatchingAttributes(org.w3c.dom.Element e1, org.w3c.dom.Element e2)`
`static boolean` | `haveMatchingChildren(org.w3c.dom.Element e1, org.w3c.dom.Element e2)` Recursively compares the children in the Element sub-trees to see if they are of equal name, value, and order.
`static org.w3c.dom.Node` | `moveSubTree(org.w3c.dom.Node from, org.w3c.dom.Node to)` Copies all child nodes from the first Element tree into the second Element tree.
`static org.w3c.dom.Node` | `moveSubTree(org.w3c.dom.Node from, org.w3c.dom.Node to, org.w3c.dom.Node context)` Copies all child nodes from the first Element tree into the second Element tree inserted before the given context node.
`static QName` | `parseQName(java.lang.String qname, org.w3c.dom.Element namespaceContext)` Parses the given String into a QName object and resolves the prefix to a namespace URI.
`static QName` | `parseSchemaName(java.lang.String name, org.w3c.dom.Element namespaceContext)`
`static java.lang.String` | `resolveNamespace(java.lang.String qname, org.w3c.dom.Node xml)` Parses the prefix from the given qualified name and finds the first XML namespace declaration that maps that prefix to a namespace URI.
`static void` | `setElement(org.w3c.dom.Element context, QName qname, org.w3c.dom.Node node, boolean embedChildren)` If the given context node has no child Elements with the given name, one is created; otherwise, the first direct child with the name is used.
`static void` | `setElement(org.w3c.dom.Element context, QName qname, java.lang.Object value)` If the given context node has no child Elements with the given name, one is created; otherwise, the first direct child with the name is used.
`static void` | `setElementText(org.w3c.dom.Element element, java.lang.String text)` If the given Element has no text content, a new Text node added with the given text; otherwise, the first Text node will have its value changed to the given text.
`static void` | `setNamespaceAttribute(org.w3c.dom.Element element, java.lang.String prefix, java.lang.String namespaceURI)` Adds a new XML namespace declaration attribute to the given Element.
`static void` | `toFile(org.w3c.dom.Node xml, java.io.File file)` This is a convenience method that calls toFile(Node, File, boolean) with the last parameter set to "true" (to add the standard XML header to the new XML file).
`static void` | `toFile(org.w3c.dom.Node xml, java.io.File file, boolean printHeader)` Serializes the given XML sub-tree to the given file.
`static java.lang.String` | `toString(org.w3c.dom.Node xml)` This is a convenience method that serializes the given XML tree with the XML header and indentation; it is the equivalent of calling toString(Node, boolean) with the last parameter set to "true".
`static java.lang.String` | `toString(org.w3c.dom.Node xml, boolean printHeader)` This is a convenience method that serializes the given XML tree with indentation; the XML header is included if the second parameter is "true".
`static java.lang.String` | `toString(org.w3c.dom.Node xml, boolean printHeader, boolean printIndents)` Serializes the given XML tree to string form, including the standard XML header and indentation if desired.
`static java.lang.String` | `toString(QName qname)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### EMPTY_DOC

    public static final org.w3c.dom.Document EMPTY_DOC

  An empty Document that can be used as a DOM factory for creation of random XML fragments. This should NOT be used by callers that want to build new fragments and attach them to a Document - this is merely a scratch pad for creating new DOM components without having to make a new Document each time. There are no guarantees as to the content of the empty Document, but you should never append children.

### TARGET_NS

    public static final java.lang.String TARGET_NS

  The targetNamespace attribute name.

  See Also:
    Constant Field Values

### XML_HEADER

    public static final java.lang.String XML_HEADER

  The standard XML document header - does not include encoding.

  See Also:
    Constant Field Values

### XMLNS_PREFIX

    public static final java.lang.String XMLNS_PREFIX

  Standard prefix for XML namespace attributes.

  See Also:
    Constant Field Values

Constructor Detail

### XmlUtils

    public XmlUtils()

Method Detail

### convertToArray

    public static org.w3c.dom.Node[] convertToArray(org.w3c.dom.NodeList list)

  Parameters:
    `list` - The list of Nodes to copy into a Node array.
  Returns:
    An array holding a copy of the Nodes in the original NodeList.

### convertToNode

    public static org.w3c.dom.Node convertToNode(org.w3c.dom.Document document,
                                                 java.lang.Object value)

  Converts an object into its XML representation; this usually means that the object's toString() method is called and the result used to create a DOM Text object. Special consideration is given to the java.util.Date and javax.xml.namespace.QName classes to ensure that they are serialized properly. If the value is a DOM object, it is simply imported into the given Document and returned.

  Parameters:
    `document` - The Document that will be used to create the new Node (or import the existing one, if the value is already a Node).
    `value` - The value that will be converted into a DOM Node.
  Returns:
    The given value, in a DOM Text node. If the given value was already a DOM Node, it will be imported into the given Document and returned. If the value is null, null is returned.

### createDocument

    public static org.w3c.dom.Document createDocument()

  Returns:
    A new DOM Document.

### createDocument

    public static org.w3c.dom.Document createDocument(java.io.File file)
                                               throws java.io.IOException,
                                                      org.xml.sax.SAXException

  Parameters:
    `file` - The XML file to parse.
  Returns:
    A new DOM Document with the contents of the given XML file.
  Throws:
    `java.io.IOException` -
    - If there is an error finding or reading from the file.
    `org.xml.sax.SAXException` -
    - If the file does not contain valid a XML document.

### createDocument

    public static org.w3c.dom.Document createDocument(org.xml.sax.InputSource source)
                                               throws java.io.IOException,
                                                      org.xml.sax.SAXException

  Parameters:
    `source` - A SAX InputSource that points to a valid XML document.
  Returns:
    A new DOM Document with the contents of the given XML data.
  Throws:
    `java.io.IOException` -
    - If there is an error reading the data from the source; this exception is usually generated when the input source is file or network-based.
    `org.xml.sax.SAXException` -
    - If the stream does not contain a valid XML document.

### createDocument

    public static org.w3c.dom.Document createDocument(java.io.InputStream stream)
                                               throws java.io.IOException,
                                                      org.xml.sax.SAXException

  Parameters:
    `stream` - A stream containing a valid XML document.
  Returns:
    A new DOM Document with the contents of the given XML data.
  Throws:
    `java.io.IOException` -
    - If there is an error reading the bytes in the stream; this exception is usually generated when the input source is file or network-based.
    `org.xml.sax.SAXException` -
    - If the stream does not contain a valid XML document.

### createDocument

    public static org.w3c.dom.Document createDocument(java.lang.String xml)
                                               throws java.io.IOException,
                                                      org.xml.sax.SAXException

  Parameters:
    `xml` - A string containing a valid XML document.
  Returns:
    A new DOM Document with the contents of the given XML string.
  Throws:
    `java.io.IOException` -
    - If there is an error reading the bytes in the string, which is highly unlikely; this exception is usually generated when the input source is file or network-based.
    `org.xml.sax.SAXException` -
    - If the string does not contain a valid XML document.

### createDocument

    public static org.w3c.dom.Document createDocument(java.net.URI uri)
                                               throws java.io.IOException,
                                                      org.xml.sax.SAXException

  This is a convenience method that converts the given URI to a File and invokes createDocument(File).

  Parameters:
    `uri` - The URI of the XML file to parse.
  Throws:
    `java.io.IOException`
    `org.xml.sax.SAXException`
  See Also:
    `createDocument(File)`

### createElement

    public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                    QName qname)

  Parameters:
    `doc` - The Document that is the owner for the new Element.
    `qname` - The QName of the new Element.
  Returns:
    A new, empty Element whose owner the given Document.

### createElement

    public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                    QName qname,
                                                    org.w3c.dom.Node value,
                                                    boolean embedChildren)

  Parameters:
    `doc` - The Document that is the owner for the new Element.
    `qname` - The Qname of the new Element.
    `value` - The value of the new Element - this is either a child element or the actual element. The fourth parameter is used to determine how the value is set.
    `embedChildren` - True if the third parameter's children should be extracted and appended to the new Element; false if the third parameter should simply be appended as a child of the new Element.
    Example: If the QName of the new element is "Type1" and the third parameter is a Node representing the following XML fragment:
    `<Type2>
    <Type3/>
    </Type2>
    `
    then setting this fourth parameter to "true" will result in a new Element that looks like this:
    `<Type1>
    <Type3/>
    </Type1>
    `
    whereas setting it to "false" will result in this:
    `<Type1>
    <Type2>
    <Type3/>
    <Type2>
    </Type1>`
    As you can see, setting this parameter to "true" discards the root of the value Node.
  Returns:
    A new Element whose owner is the given Document and whose children are imported from the given value Node (see fourth parameter details).

### createElement

    public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                    QName qname,
                                                    java.lang.Object value)

  Parameters:
    `doc` - The Document that is the owner of the new Element.
    `qname` - The QName of the new Element.
    `value` - The value of the new Element. If this is a DOM Node, it's children will be embedded into the new Element and the root node discarded. If it is not a DOM Node, it will be converted into one using convertToNode(Document, Object) and be appended to the new Element as a Text node.
  Returns:
    A new Element whose owner is the given Document and whose value is either the string representation of the given value or - if the value is a DOM Node - the children of the value.
  See Also:
    `convertToNode(Document, Object)`, `createElement(Document, QName, Node, boolean)`

### createElement

    public static org.w3c.dom.Element createElement(QName qname)

  This is a convenience method that creates a new, empty Element; the owner of the Element is EMPTY_DOC.

  See Also:
    `createElement(QName, Object)`

### createElement

    public static org.w3c.dom.Element createElement(QName qname,
                                                    java.lang.Object value)

  This is a convenience method that creates a new Element with the given value; the owner of the Element is EMPTY_DOC.

  See Also:
    `EMPTY_DOC`, `createElement(Document, QName, Object)`

### equals

    public static boolean equals(org.w3c.dom.Element e1,
                                 org.w3c.dom.Element e2)

  Parameters:
    `e1` -
    `e2` -
  Returns:
    True, if:
    - The two Elements have the same QName.
    - They have the same child elements, in the same order; this includes Elements and Texts.
    - They have the same attributes, excluding XML namespace and prefix definitions.
    This method short-circuits to "true" if the two references are the same (e1 == e2). It short-circuits to "false" if one reference is null and the other isn't.

### extractText

    public static java.lang.String extractText(org.w3c.dom.Element element)

  Parameters:
    `element` - The Element that may or may not have Text nodes.
  Returns:
    The content of the first child Text node in the Element. The method returns null if the Element has no text.

### findFirstInSubTree

    public static org.w3c.dom.Element findFirstInSubTree(org.w3c.dom.Element context,
                                                         QName qname)

  This is a convenience method that returns the first Element in the array returned by findInSubTree(Element, QName), if any.

  Parameters:
    `context` - The root node from which the search will be done.
    `qname` - The QName of the Element to search for.
  Returns:
    The first occurrence of a child Element with the given name. The Element may be anywhere in the sub-tree, meaning it may not be a direct child of the context node. The only guarantee is that it is somewhere beneath the context node. The method returns null if no occurrences are found.
  See Also:
    `findInSubTree(Element, QName)`

### findInSubTree

    public static org.w3c.dom.Element[] findInSubTree(org.w3c.dom.Element context,
                                                      QName qname)

  Searches through an entire sub-tree for child Elements whose QName matches the one given. The results are not guaranteed to be in any particular order, and are not limited to direct children of the given context node.
  If you want to limit your search for Elements to the direct children of a given Element, use the getAllElement, getElement, and getElements methods. Those guarantee that all results are directly beneath the given context.

  Parameters:
    `context` - The root node from which the search will be done.
    `qname` - The QName of the Element to search for.
  Returns:
    An array with all occurrences of child Elements with the given name. The Elements may be anywhere in the sub-tree, meaning they may not be direct children of the context node. The only guarantee is that they are somewhere beneath the context node. The method returns an empty array if no occurrences are found.
  See Also:
    `Element.getElementsByTagNameNS(String, String)`, `getAllElements(Node)`, `getElement(Node, QName)`, `getElements(Node, QName)`

### getAllElements

    public static org.w3c.dom.Element[] getAllElements(org.w3c.dom.Node context)

  Parameters:
    `context` - The Node whose direct child Elements will be returned.
  Returns:
    All Elements that are direct children of the given Node, regardless of namespace URI or name. The method returns an empty array if no children exist.

### getAllElements

    public static org.w3c.dom.Element[] getAllElements(org.w3c.dom.Node context,
                                                       java.lang.String namespace)

  Parameters:
    `context` - The Node whose direct child Elements will be returned.
    `namespace` - The namespace URI to match against all child Elements. All returned results will have QNames with this namespace.
  Returns:
    The set of direct child Elements whose QNames have the given namespace URI. The method returns an empty array if there are no children that belong the namespace.

### getAllElements

    public static org.w3c.dom.Element[] getAllElements(org.w3c.dom.Node context,
                                                       java.lang.String namespace,
                                                       java.lang.String localName)

  Parameters:
    `context` - The Node whose direct child Elements will be returned.
    `namespace` - The namespace URI to match against all child Elements. All returned results will have QNames with this namespace.
    `localName` - The local (non-prefixed) name to match against all child Elements. All returned results will have QNames with this name.
  Returns:
    The set of direct child Elements whose QNames have the given namespace URI and name. The method returns an empty array if no children have such a QName.

### getAllNamespaces

    public static java.util.Map getAllNamespaces(org.w3c.dom.Element xml)

  Searches the given sub-tree and returns all of the namespace URIs that are used to declare the root Element and its child Elements. It does not return other namespace definitions that are included in those elements - just the ones that are used in the QNames of the Elements themselves. The Map that is returned is a Map[prefix, namespace].

  Parameters:
    `xml` - The root of the sub-tree to perform the search on.
  Returns:
    A Map containing all namespaces used in Element QNames. The Map is keyed by the namespace prefixes. The Map does not include namespaces outside of the Element QNames.

### getAttribute

    public static java.lang.String getAttribute(org.w3c.dom.Element xml,
                                                QName qname)

### getBoolean

    public static java.lang.Boolean getBoolean(org.w3c.dom.Element xml)

  Returns:
    The Boolean value represented by the Element's text.

### getDate

    public static java.util.Date getDate(org.w3c.dom.Element xml)
                                  throws java.text.ParseException

  Returns:
    The date value represented by the Element's text, or null if the Element had no text value.
  Throws:
    `java.text.ParseException` -
    - If the text is not in XSD date format.
  See Also:
    `XsdUtils.getLocalTime(String)`

### getDocumentRoot

    public static org.w3c.dom.Element getDocumentRoot(org.w3c.dom.Node xml)

  Parameters:
    `xml` -
  Returns:
    The root Element of the Document that owns the given Node.

### getDouble

    public static java.lang.Double getDouble(org.w3c.dom.Element xml)

  Returns:
    The double value represented by the Element's text.

### getElement

    public static org.w3c.dom.Element getElement(org.w3c.dom.Node context,
                                                 QName qname)

  This is a convenience method that returns the zeroth child Element under the given Node. It is equivalent to calling the getElement(Node, QName, int) method with zero as the last parameter.

  Parameters:
    `context` - The root Node to perform the search on.
    `qname` - The QName to search for.
  Returns:
    The first direct child Element with the given QName.
  See Also:
    `getElement(Node, QName, int)`

### getElement

    public static org.w3c.dom.Element getElement(org.w3c.dom.Node context,
                                                 QName qname,
                                                 int index)

  Parameters:
    `context` - The root Node to perform the search on.
    `qname` - The QName to search for.
    `index` - The occurrence of QName to return (zero-based). If index is 0, the first match is returned, if it's 3, the fourth match is returned, etc.
  Returns:
    The n-th direct child Element with the given QName. The method returns null if there are no children with that QName.

### getElementQName

    public static QName getElementQName(org.w3c.dom.Element xml)

  Parameters:
    `xml` - The Element whose QName will be returned.
  Returns:
    The QName of the given Element definition.

### getElements

    public static org.w3c.dom.Element[] getElements(org.w3c.dom.Node context,
                                                    QName qname)

  Parameters:
    `context` - The root node to perform the search on.
    `qname` - The QName to search for.
  Returns:
    All direct child Elements that have the given QName.

### getElementsText

    public static java.lang.String[] getElementsText(org.w3c.dom.Node context,
                                                     QName qname)

  Searches a sub-tree for all direct child Elements with the given Qname and returns the text content of those Elements, if any.

  Parameters:
    `context` - The root node to perform the search on.
    `qname` - The QName to search for.
  Returns:
    The text content of the matching children, in order; if a matching child did not have any text, its String is null.
  See Also:
    `extractText(Element)`, `getElementText(Node, QName)`

### getElementText

    public static java.lang.String getElementText(org.w3c.dom.Node context,
                                                  QName qname)

  Searches a sub-tree for an Element with the given QName, and then returns its text content, if any.
  Example: If the context node points to an Element like this:
  `<Type1>
  <Type2>here is some text</Type2>
  </Type1>`
  and you pass "Type2" as the second parameter, "here is some text" will be the return value. Note that this search only applies to direct children.

  Parameters:
    `context` - The root Node to perform the search on.
    `qname` - The QName to search for.
  Returns:
    The text of the first child Element with the given QName.
  See Also:
    `extractText(Element)`

### getFirstElement

    public static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node context)

  Parameters:
    `context` - The root Node to perform the search against.
  Returns:
    The first direct child Element. The method returns null if the given node has no children.

### getFloat

    public static java.lang.Float getFloat(org.w3c.dom.Element xml)

  Returns:
    The float value represented by the Element's text.

### getHashCode

    public static int getHashCode(org.w3c.dom.Element xml)

  Parameters:
    `xml` -
  Returns:
    Calculates a hash code for the DOM Element based on its text value and the hash codes of any child elements (the function recurses through the sub-tree). DOM does not specify a standard hashCode() for DOM Nodes, so this method gives us some standard behavior to rely on.

### getInteger

    public static java.lang.Integer getInteger(org.w3c.dom.Element xml)

  Returns:
    The integer value represented by the Element's text.

### getLong

    public static java.lang.Long getLong(org.w3c.dom.Element xml)

  Returns:
    The long value represented by the Element's text.

### getQName

    public static QName getQName(org.w3c.dom.Element xml)

  Retrieves the text from the element specified and parses it into a fully-resolved QName.

  Parameters:
    `xml` -
  Returns:
    A fully-resolved QName, or null if there was no text.

### getQNameFromChild

    public static QName getQNameFromChild(org.w3c.dom.Element xml,
                                          QName childQName)

  Retrieves the text from the child element specified and parses it into a fully-resolved QName.

  Parameters:
    `xml` - The root Element to perform the search on.
    `childQName` - The name of the child element whose text is a QName.
  Returns:
    A fully-resolved QName, or null if there was no text.

### getShort

    public static java.lang.Short getShort(org.w3c.dom.Element xml)

  Returns:
    The short value represented by the Element's text.

### haveMatchingAttributes

    public static boolean haveMatchingAttributes(org.w3c.dom.Element e1,
                                                 org.w3c.dom.Element e2)

  Parameters:
    `e1` -
    `e2` -
  Returns:
    True if the two Elements have the same attributes and attribute values. The comparison excludes XML namespace declarations, since the prefixes used in an XML fragment are not important.

### haveMatchingChildren

    public static boolean haveMatchingChildren(org.w3c.dom.Element e1,
                                               org.w3c.dom.Element e2)

  Recursively compares the children in the Element sub-trees to see if they are of equal name, value, and order. Only Element and Text nodes are compared.

  Parameters:
    `e1` -
    `e2` -
  Returns:
    True if the two Elements have the same children, in the same order. The comparison only targets Element and Text children, not Attr or other DOM Nodes.
  See Also:
    `haveMatchingAttributes(Element, Element)`

### moveSubTree

    public static org.w3c.dom.Node moveSubTree(org.w3c.dom.Node from,
                                               org.w3c.dom.Node to)

  Copies all child nodes from the first Element tree into the second Element tree. Because a Node cannot have two parents, all of the children will be removed from the first tree before being appended to the second one.

  Parameters:
    `from` - The sub-tree to copy Nodes from.
    `to` - The sub-tree to copy Nodes to.
  Returns:
    The same Node as the second parameter (the new sub-tree).

### moveSubTree

    public static org.w3c.dom.Node moveSubTree(org.w3c.dom.Node from,
                                               org.w3c.dom.Node to,
                                               org.w3c.dom.Node context)

  Copies all child nodes from the first Element tree into the second Element tree inserted before the given context node. Because a Node cannot have two parents, all of the children will be removed from the first tree before being appended to the second one. If the context node is null, the new nodes will simply be appended to the list of children of the second Element tree.

  Parameters:
    `from` - The sub-tree to copy Nodes from.
    `to` - The sub-tree to copy Nodes to.
    `context` - The Node before which the children will be inserted
  Returns:
    The same Node as the second parameter (the new sub-tree).

### parseQName

    public static QName parseQName(java.lang.String qname,
                                   org.w3c.dom.Element namespaceContext)

  Parses the given String into a QName object and resolves the prefix to a namespace URI. The search for a valid namespace URI starts with the given context Element and continues up to the root of the XML Document. If no matching namespace can be found, the QName will have a null namespace URI.

  Parameters:
    `qname` - The qualified name, in string form.
    `namespaceContext` - The Element from which to start namespace resolution. The search will start with this Element and move up through its parents until a match is found or the root is hit.
  Returns:
    A QName object with a proper namespace URI, if one is defined.
  See Also:
    `resolveNamespace(String, Node)`

### parseSchemaName

    public static QName parseSchemaName(java.lang.String name,
                                        org.w3c.dom.Element namespaceContext)

  Parameters:
    `name` - The unqualified name that must be matched to a schema namespace to become qualified.
    `namespaceContext` - The node from which the target namespace resolution will occur.
  Returns:
    A qualified name, where the local part is the given name, the namespace URI is the schema's target namespace, and the prefix is muse-op.

### resolveNamespace

    public static java.lang.String resolveNamespace(java.lang.String qname,
                                                    org.w3c.dom.Node xml)

  Parses the prefix from the given qualified name and finds the first XML namespace declaration that maps that prefix to a namespace URI. If there is no prefix, the method searches for the targetNamespace attribute instead. The search starts with the give Node and moves up the XML Document until a match is found or the root of the Document is reached.

  Parameters:
    `qname` - The qualified name whose prefix is searched for.
    `xml` - The Node from which namespace resolution will start.
  Returns:
    The namespace URI that the QName's prefix is associated with. The method returns null if no match is found.

### setElement

    public static void setElement(org.w3c.dom.Element context,
                                  QName qname,
                                  org.w3c.dom.Node node,
                                  boolean embedChildren)

  If the given context node has no child Elements with the given name, one is created; otherwise, the first direct child with the name is used. Either way, the match is assigned the given value, using the rules described in createElement(Document, QName, Node, boolean).

  See Also:
    `createElement(Document, QName, Node, boolean)`

### setElement

    public static void setElement(org.w3c.dom.Element context,
                                  QName qname,
                                  java.lang.Object value)

  If the given context node has no child Elements with the given name, one is created; otherwise, the first direct child with the name is used. Either way, the match is assigned the given value, using the rules described in createElement(Document, QName, Object).

  See Also:
    `createElement(Document, QName, Object)`

### setElementText

    public static void setElementText(org.w3c.dom.Element element,
                                      java.lang.String text)

  If the given Element has no text content, a new Text node added with the given text; otherwise, the first Text node will have its value changed to the given text. If your Element has mixed content and you want to change the n-th Text Element, you're on your own.

  Parameters:
    `element` - The Element whose text content will be modified.
    `text` - The new text value.

### setNamespaceAttribute

    public static void setNamespaceAttribute(org.w3c.dom.Element element,
                                             java.lang.String prefix,
                                             java.lang.String namespaceURI)

  Adds a new XML namespace declaration attribute to the given Element. The new attribute is of the form xmlns:prefix=namespace

  Parameters:
    `element` -
    `prefix` -
    `namespaceURI` -

### toFile

    public static void toFile(org.w3c.dom.Node xml,
                              java.io.File file)
                       throws java.io.IOException

  This is a convenience method that calls toFile(Node, File, boolean) with the last parameter set to "true" (to add the standard XML header to the new XML file).

  Throws:
    `java.io.IOException`
  See Also:
    `toFile(Node, File, boolean)`

### toFile

    public static void toFile(org.w3c.dom.Node xml,
                              java.io.File file,
                              boolean printHeader)
                       throws java.io.IOException

  Serializes the given XML sub-tree to the given file.

  Parameters:
    `xml` - The XML tree to serialize - must be a Document or Element.
    `file` - The file to write to. If it already exists, its contents will be overwritten; if it does not, it will be created.
    `printHeader` - True if the standard XML document header should be added to the top of the file.
  Throws:
    `java.io.IOException` -
    - If there is an error creating, opening, or while writing to the file.
  See Also:
    `toString(Node, boolean)`

### toString

    public static java.lang.String toString(org.w3c.dom.Node xml)

  This is a convenience method that serializes the given XML tree with the XML header and indentation; it is the equivalent of calling toString(Node, boolean) with the last parameter set to "true".

  See Also:
    `toString(Node, boolean)`

### toString

    public static java.lang.String toString(org.w3c.dom.Node xml,
                                            boolean printHeader)

  This is a convenience method that serializes the given XML tree with indentation; the XML header is included if the second parameter is "true".

  See Also:
    `toString(Node, boolean, boolean)`

### toString

    public static java.lang.String toString(org.w3c.dom.Node xml,
                                            boolean printHeader,
                                            boolean printIndents)

  Serializes the given XML tree to string form, including the standard XML header and indentation if desired. This method relies on the serialization API from Apache Xerces, since JAXP has on equivalent.

  Parameters:
    `xml` - The XML tree to serialize.
    `printHeader` - True if you want the XML header printed before the XML.
    `printIndents` - True if you want pretty-printing - child elements will be indented with symmetry.
  Returns:
    The string representation of the given Node.

### toString

    public static java.lang.String toString(QName qname)

  Parameters:
    `qname` - The QName to serialize into prefix:localName form.
  Returns:
    This method returns a different value than QName.toString(). The QName.toString() returns a string of the format:
    {namespace URI}:name
    whereas this method returns:
    prefix:name
    which is a valid representation to put into XML documents. If the QName has no prefix, the local name is returned.

Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD