org.exist.fluent
Class QName

java.lang.Object
  extended by javax.xml.namespace.QName
      extended by org.exist.fluent.QName
All Implemented Interfaces:
Serializable, Comparable<QName>

public class QName
extends QName
implements Comparable<QName>

A qualified name, consisting of a namespace and a local name.

Author:
Piotr Kaminski
See Also:
Serialized Form

Constructor Summary
QName(String namespace, String localName, String prefix)
          Create a qualified name.
 
Method Summary
 int compareTo(QName o)
           
 Attr createAttribute(Document doc)
          Create an attribute in the given document whose name is this qualified name.
 Element createElement(Document doc)
          Create an element in the given document whose tag is this qualified name.
 Attr getAttributeNode(Element elem)
          Get the attribute with this qualified name from the given element.
 String getTag()
          Get the XML tag for this qualified name, either prefix:localName or just localName if there is no prefix.
 boolean hasNamespace()
          Return whether this qualified name is actually qualified by a namespace or not.
static QName of(Node node)
          Return the qualified name of the given node.
static QName parse(String tag, NamespaceMap namespaces)
          Parse the given tag into a qualified name within the context of the given namespace bindings.
static QName parse(String tag, NamespaceMap namespaces, String defaultNamespace)
          Parse the given tag into a qualified name within the context of the given namespace bindings, overriding the default namespace binding with the given one.
 void setAttribute(Element elem, String value)
          Set an attribute value on the given element, where the attribute's name is this qualified name.
 
Methods inherited from class javax.xml.namespace.QName
equals, getLocalPart, getNamespaceURI, getPrefix, hashCode, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QName

public QName(String namespace,
             String localName,
             String prefix)
Create a qualified name.

Parameters:
namespace - the namespace of the qualified name, null if none
localName - the local part of the qualified name, must not be null or empty
prefix - the prefix to use for the qualified name, null if default (empty) prefix
Method Detail

compareTo

public int compareTo(QName o)
Specified by:
compareTo in interface Comparable<QName>

hasNamespace

public boolean hasNamespace()
Return whether this qualified name is actually qualified by a namespace or not.

Returns:
true if the qualified name has a namespace set, false if it's just a local name

createElement

public Element createElement(Document doc)
Create an element in the given document whose tag is this qualified name. Correctly calls createElement or createElementNS depending on whether this name is actually qualified or not.

Parameters:
doc - the document to use to create the element
Returns:
a new element whose tag is this qualified name

createAttribute

public Attr createAttribute(Document doc)
Create an attribute in the given document whose name is this qualified name. Correctly calls createAttribute or createAttributeNS depending on whether this name is actually qualified or not.

Parameters:
doc - the document to use to create the attribute
Returns:
a new attribute whose name is this qualified name

setAttribute

public void setAttribute(Element elem,
                         String value)
Set an attribute value on the given element, where the attribute's name is this qualified name. Correctly calls setAttribute or setAttributeNS depending on whether this name is actually qualified or not.

Parameters:
elem - the element on which to set the attribute
value - the value of the attribute

getAttributeNode

public Attr getAttributeNode(Element elem)
Get the attribute with this qualified name from the given element. Correctly calls getAttributeNode or getAttributeNodeNS depending on whether this name is actually qualified or not.

Parameters:
elem - the element to read the attribute from
Returns:
the attribute node with this qualified name

getTag

public String getTag()
Get the XML tag for this qualified name, either prefix:localName or just localName if there is no prefix. Be careful: this tag is dependent on namespace context for correct interpretation.

Returns:
the XML tag for this qname, based on the qualified name's prefix and localName

of

public static QName of(Node node)
Return the qualified name of the given node.

Parameters:
node - the target node
Returns:
the node's qualified name

parse

public static QName parse(String tag,
                          NamespaceMap namespaces)
Parse the given tag into a qualified name within the context of the given namespace bindings.

Parameters:
tag - the tag to parse, in standard XML format
namespaces - the namespace bindings to use
Returns:
the qualified name of the given tag

parse

public static QName parse(String tag,
                          NamespaceMap namespaces,
                          String defaultNamespace)
Parse the given tag into a qualified name within the context of the given namespace bindings, overriding the default namespace binding with the given one. This is useful for parsing attribute names, where a lack of prefix should be interpreted as no namespace rather than the default namespace currently in effect.

Parameters:
tag - the tag to parse, in standard XML format
namespaces - the namespace bindings to use
defaultNamespace - the URI to use as the default namespace, in preference to any specified in the namespace bindings
Returns:
the qualified name of the given tag


Copyright (C) All rights reserved.