org.apache.muse.util.xml
Class XmlUtils

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

public class XmlUtils
extends 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 Document EMPTY_DOC
          An empty Document that can be used as a DOM factory for creation of random XML fragments.
static String TARGET_NS
          The targetNamespace attribute name.
static String XML_HEADER
          The standard XML document header - does not include encoding.
static String XMLNS_PREFIX
          Standard prefix for XML namespace attributes.
 
Constructor Summary
XmlUtils()
           
 
Method Summary
static Node[] convertToArray(NodeList list)
           
static Node convertToNode(Document document, 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 Document createDocument()
           
static Document createDocument(File file)
           
static Document createDocument(InputSource source)
           
static Document createDocument(InputStream stream)
           
static Document createDocument(String xml)
           
static Document createDocument(URI uri)
          This is a convenience method that converts the given URI to a File and invokes createDocument(File).
static Element createElement(Document doc, QName qname)
           
static Element createElement(Document doc, QName qname, Node value, boolean embedChildren)
           
static Element createElement(Document doc, QName qname, Object value)
           
static Element createElement(QName qname)
          This is a convenience method that creates a new, empty Element; the owner of the Element is EMPTY_DOC.
static Element createElement(QName qname, 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(Element e1, Element e2)
           
static String extractText(Element element)
           
static Element findFirstInSubTree(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 Element[] findInSubTree(Element context, QName qname)
          Searches through an entire sub-tree for child Elements whose QName matches the one given.
static Element[] getAllElements(Node context)
           
static Element[] getAllElements(Node context, String namespace)
           
static Element[] getAllElements(Node context, String namespace, String localName)
           
static Map getAllNamespaces(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 String getAttribute(Element xml, QName qname)
           
static Boolean getBoolean(Element xml)
           
static Date getDate(Element xml)
           
static Element getDocumentRoot(Node xml)
           
static Double getDouble(Element xml)
           
static Element getElement(Node context, QName qname)
          This is a convenience method that returns the zeroth child Element under the given Node.
static Element getElement(Node context, QName qname, int index)
           
static QName getElementQName(Element xml)
           
static Element[] getElements(Node context, QName qname)
           
static String[] getElementsText(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 String getElementText(Node context, QName qname)
          Searches a sub-tree for an Element with the given QName, and then returns its text content, if any.
static Element getFirstElement(Node context)
           
static Float getFloat(Element xml)
           
static int getHashCode(Element xml)
           
static Integer getInteger(Element xml)
           
static Long getLong(Element xml)
           
static QName getQName(Element xml)
          Retrieves the text from the element specified and parses it into a fully-resolved QName.
static QName getQNameFromChild(Element xml, QName childQName)
          Retrieves the text from the child element specified and parses it into a fully-resolved QName.
static Short getShort(Element xml)
           
static boolean haveMatchingAttributes(Element e1, Element e2)
           
static boolean haveMatchingChildren(Element e1, Element e2)
          Recursively compares the children in the Element sub-trees to see if they are of equal name, value, and order.
static Node moveSubTree(Node from, Node to)
          Copies all child nodes from the first Element tree into the second Element tree.
static Node moveSubTree(Node from, Node to, 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(String qname, Element namespaceContext)
          Parses the given String into a QName object and resolves the prefix to a namespace URI.
static QName parseSchemaName(String name, Element namespaceContext)
           
static String resolveNamespace(String qname, 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(Element context, QName qname, 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(Element context, QName qname, 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(Element element, 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(Element element, String prefix, String namespaceURI)
          Adds a new XML namespace declaration attribute to the given Element.
static void toFile(Node xml, 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(Node xml, File file, boolean printHeader)
          Serializes the given XML sub-tree to the given file.
static String toString(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 String toString(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 String toString(Node xml, boolean printHeader, boolean printIndents)
          Serializes the given XML tree to string form, including the standard XML header and indentation if desired.
static 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 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 String TARGET_NS
The targetNamespace attribute name.

See Also:
Constant Field Values

XML_HEADER

public static final String XML_HEADER
The standard XML document header - does not include encoding.

See Also:
Constant Field Values

XMLNS_PREFIX

public static final String XMLNS_PREFIX
Standard prefix for XML namespace attributes.

See Also:
Constant Field Values
Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

convertToArray

public static Node[] convertToArray(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 Node convertToNode(Document document,
                                 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 Document createDocument()
Returns:
A new DOM Document.

createDocument

public static Document createDocument(File file)
                               throws IOException,
                                      SAXException
Parameters:
file - The XML file to parse.
Returns:
A new DOM Document with the contents of the given XML file.
Throws:
IOException -
  • If there is an error finding or reading from the file.
SAXException -
  • If the file does not contain valid a XML document.

createDocument

public static Document createDocument(InputSource source)
                               throws IOException,
                                      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:
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.
SAXException -
  • If the stream does not contain a valid XML document.

createDocument

public static Document createDocument(InputStream stream)
                               throws IOException,
                                      SAXException
Parameters:
stream - A stream containing a valid XML document.
Returns:
A new DOM Document with the contents of the given XML data.
Throws:
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.
SAXException -
  • If the stream does not contain a valid XML document.

createDocument

public static Document createDocument(String xml)
                               throws IOException,
                                      SAXException
Parameters:
xml - A string containing a valid XML document.
Returns:
A new DOM Document with the contents of the given XML string.
Throws:
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.
SAXException -
  • If the string does not contain a valid XML document.

createDocument

public static Document createDocument(URI uri)
                               throws IOException,
                                      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:
IOException
SAXException
See Also:
createDocument(File)

createElement

public static Element createElement(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 Element createElement(Document doc,
                                    QName qname,
                                    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 Element createElement(Document doc,
                                    QName qname,
                                    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 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 Element createElement(QName qname,
                                    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(Element e1,
                             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 String extractText(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 Element findFirstInSubTree(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 Element[] findInSubTree(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 Element[] getAllElements(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 Element[] getAllElements(Node context,
                                       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 Element[] getAllElements(Node context,
                                       String namespace,
                                       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 Map getAllNamespaces(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 String getAttribute(Element xml,
                                  QName qname)

getBoolean

public static Boolean getBoolean(Element xml)
Returns:
The Boolean value represented by the Element's text.

getDate

public static Date getDate(Element xml)
                    throws ParseException
Returns:
The date value represented by the Element's text, or null if the Element had no text value.
Throws:
ParseException -
  • If the text is not in XSD date format.
See Also:
XsdUtils.getLocalTime(String)

getDocumentRoot

public static Element getDocumentRoot(Node xml)
Parameters:
xml -
Returns:
The root Element of the Document that owns the given Node.

getDouble

public static Double getDouble(Element xml)
Returns:
The double value represented by the Element's text.

getElement

public static Element getElement(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 Element getElement(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(Element xml)
Parameters:
xml - The Element whose QName will be returned.
Returns:
The QName of the given Element definition.

getElements

public static Element[] getElements(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 String[] getElementsText(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 String getElementText(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 Element getFirstElement(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 Float getFloat(Element xml)
Returns:
The float value represented by the Element's text.

getHashCode

public static int getHashCode(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 Integer getInteger(Element xml)
Returns:
The integer value represented by the Element's text.

getLong

public static Long getLong(Element xml)
Returns:
The long value represented by the Element's text.

getQName

public static QName getQName(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(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 Short getShort(Element xml)
Returns:
The short value represented by the Element's text.

haveMatchingAttributes

public static boolean haveMatchingAttributes(Element e1,
                                             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(Element e1,
                                           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 Node moveSubTree(Node from,
                               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 Node moveSubTree(Node from,
                               Node to,
                               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(String qname,
                               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(String name,
                                    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 String resolveNamespace(String qname,
                                      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(Element context,
                              QName qname,
                              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(Element context,
                              QName qname,
                              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(Element element,
                                  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(Element element,
                                         String prefix,
                                         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(Node xml,
                          File file)
                   throws 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:
IOException
See Also:
toFile(Node, File, boolean)

toFile

public static void toFile(Node xml,
                          File file,
                          boolean printHeader)
                   throws 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:
IOException -
  • If there is an error creating, opening, or while writing to the file.
See Also:
toString(Node, boolean)

toString

public static String toString(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 String toString(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 String toString(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 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.


Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.