com.icl.saxon.tree

Class ElementWithAttributes

Implemented Interfaces:
DOMLocator, Element, NamedNodeMap, Node, NodeInfo, Source, SourceLocator
Known Direct Subclasses:
StyleElement

public class ElementWithAttributes
extends ElementImpl
implements Element, NamedNodeMap

A node in the XML parse tree representing an XML element.

This class is an implementation of NodeInfo

Field Summary

protected AttributeCollection
attributeList
protected int[]
namespaceList

Fields inherited from class com.icl.saxon.tree.ElementImpl

nameCode, root

Fields inherited from class com.icl.saxon.tree.ParentNodeImpl

sequence

Fields inherited from class com.icl.saxon.tree.NodeImpl

emptyArray, index, parent

Fields inherited from class com.icl.saxon.om.AbstractNode

NODE_LETTER

Fields inherited from interface com.icl.saxon.om.NodeInfo

ATTRIBUTE, COMMENT, ELEMENT, NAMESPACE, NODE, NONE, NUMBER_OF_TYPES, PI, ROOT, TEXT

Method Summary

void
addNamespaceNodes(ElementImpl owner, Vector list, boolean addXML)
Make the set of all namespace nodes associated with this element.
void
copy(Outputter out, boolean allNamespaces)
Copy this node to a given outputter (supporting xsl:copy-of)
String
getAttribute(String name)
Retrieves an attribute value by name.
AttributeCollection
getAttributeList()
Get the attribute list for this element.
String
getAttributeNS(String namespaceURI, String localName)
Retrieves an attribute value by local name and namespace URI.
Attr
getAttributeNode(String name)
Retrieves an attribute node by name.
Attr
getAttributeNodeNS(String namespaceURI, String localName)
Retrieves an Attr node by local name and namespace URI.
String
getAttributeValue(String name)
Find the value of a given attribute of this element.
String
getAttributeValue(String uri, String localName)
Find the value of a given attribute of this node.
String
getAttributeValue(int fingerprint)
Get the value of a given attribute of this node
NamedNodeMap
getAttributes()
A NamedNodeMap containing the attributes of this element.
int
getLength()
Get number of attributes (DOM NamedNodeMap method).
Node
getNamedItem(String name)
Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.
Node
getNamedItemNS(String uri, String localName)
Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.
protected int[]
getNamespaceCodes()
Get the list of in-scope namespaces for this element as an array of namespace codes.
String
getPrefixForURI(String uri)
Search the NamespaceList for a given URI, returning the corresponding prefix.
short
getURICodeForPrefix(String prefix)
Search the NamespaceList for a given prefix, returning the corresponding URI.
boolean
hasAttribute(String name)
Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.
boolean
hasAttributeNS(String namespaceURI, String localName)
Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.
boolean
hasAttributes()
Returns whether this node (if it is an element) has any attributes.
void
initialise(int nameCode, AttributeCollection atts, NodeInfo parent, String baseURI, int lineNumber, int sequenceNumber)
Initialise a new ElementWithAttributes with an element name and attribute list
Node
item(int index)
Get n'th attribute (DOM NamedNodeMap method).
void
outputNamespaceNodes(Outputter out, boolean includeAncestors)
Output all namespace nodes associated with this element.
void
removeAttribute(String name)
Removes an attribute by name.
void
removeAttributeNS(String namespaceURI, String localName)
Removes an attribute by local name and namespace URI.
Attr
removeAttributeNode(Attr oldAttr)
Removes the specified attribute node.
Node
removeNamedItem(String name)
Remove named attribute (DOM NamedNodeMap method: always fails)
Node
removeNamedItemNS(String uri, String localName)
Remove named attribute (DOM NamedNodeMap method: always fails)
void
setAttribute(String name, String value)
Set the value of an attribute on the current element.
void
setAttributeNS(String namespaceURI, String qualifiedName, String value)
Adds a new attribute.
Attr
setAttributeNode(Attr newAttr)
Adds a new attribute node.
Attr
setAttributeNodeNS(Attr newAttr)
Add a new attribute.
Node
setNamedItem(Node arg)
Set named attribute (DOM NamedNodeMap method: always fails)
Node
setNamedItemNS(Node arg)
Set named attribute (DOM NamedNodeMap method: always fails)
void
setNamespaceDeclarations(int[] namespaces, int namespacesUsed)
Set the namespace declarations for the element

Methods inherited from class com.icl.saxon.tree.ElementImpl

addNamespaceNodes, copy, copy, generateId, getAttributeList, getAttributeValue, getBaseURI, getDocumentRoot, getLineNumber, getNameCode, getNodeType, getPrefixForURI, getSystemId, getURICodeForPrefix, initialise, makeNameCode, outputNamespaceNodes, setAttribute, setLineNumber, setNameCode, setSystemId

Methods inherited from class com.icl.saxon.tree.ParentNodeImpl

addChild, compact, copyStringValue, dropChildren, enumerateChildren, getChildNodes, getFirstChild, getLastChild, getNodeValue, getNthChild, getSequenceNumber, getStringValue, hasChildNodes, removeChild, renumberChildren, useChildrenArray

Methods inherited from class com.icl.saxon.tree.NodeImpl

compareOrder, generateId, getAttributeValue, getAttributeValue, getAttributes, getBaseURI, getChildNodes, getDisplayName, getDocumentElement, getDocumentRoot, getEnumeration, getFingerprint, getFirstChild, getLastChild, getLineNumber, getLocalName, getNameCode, getNamePool, getNextInDocument, getNextSibling, getOriginatingNode, getParent, getPrefix, getPreviousInDocument, getPreviousSibling, getSequenceNumber, getSystemId, getURI, hasAttributes, hasChildNodes, isSameNodeInfo, outputNamespaceNodes, removeNode, setSystemId

Methods inherited from class com.icl.saxon.om.AbstractNode

appendChild, appendData, cloneNode, compareDocumentPosition, compareOrder, copyStringValue, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, deleteData, disallowUpdate, generateId, getAttribute, getAttributeNS, getAttributeNode, getAttributeNodeNS, getAttributeValue, getAttributeValue, getAttributes, getBaseURI, getChildNodes, getColumnNumber, getData, getDisplayName, getDoctype, getDocumentElement, getDocumentRoot, getElementById, getElementsByTagName, getElementsByTagNameNS, getEnumeration, getFeature, getFingerprint, getFirstChild, getImplementation, getLastChild, getLength, getLineNumber, getLocalName, getName, getNameCode, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOriginatingNode, getOwnerDocument, getOwnerElement, getParent, getParentNode, getPrefix, getPreviousSibling, getPublicId, getSchemaTypeInfo, getSpecified, getSystemId, getTagName, getTextContent, getURI, getUserData, getValue, getWholeText, hasAttribute, hasAttributeNS, hasAttributes, hasChildNodes, importNode, insertBefore, insertData, isDefaultNamespace, isElementContentWhitespace, isEqualNode, isId, isSameNode, isSameNodeInfo, isSupported, lookupNamespaceURI, lookupPrefix, normalize, outputNamespaceNodes, removeAttribute, removeAttributeNS, removeAttributeNode, removeChild, replaceChild, replaceData, replaceWholeText, setAttributeNS, setAttributeNode, setAttributeNodeNS, setData, setIdAttribute, setIdAttributeNS, setIdAttributeNode, setNodeValue, setPrefix, setTextContent, setUserData, setValue, splitText, substringData, supports

Field Details

attributeList

protected AttributeCollection attributeList

namespaceList

protected int[] namespaceList

Method Details

addNamespaceNodes

public void addNamespaceNodes(ElementImpl owner,
                              Vector list,
                              boolean addXML)
Make the set of all namespace nodes associated with this element.
Overrides:
addNamespaceNodes in interface ElementImpl
Parameters:
owner - The element owning these namespace nodes.
list - a Vector containing NamespaceImpl objects representing the namespaces in scope for this element; the method appends nodes to this Vector, which should initially be empty. Note that the returned list will never contain the XML namespace (to get this, the NamespaceEnumeration class adds it itself). The list WILL include an entry for the undeclaration xmlns=""; again it is the job of NamespaceEnumeration to ignore this, since it doesn't represent a true namespace node.
addXML - Add a namespace node for the XML namespace

copy

public void copy(Outputter out,
                 boolean allNamespaces)
            throws TransformerException
Copy this node to a given outputter (supporting xsl:copy-of)
Overrides:
copy in interface ElementImpl
Parameters:
out - The outputter
allNamespaces - true if namespaces for ancestor nodes must be output

getAttribute

public String getAttribute(String name)
Retrieves an attribute value by name. Namespace declarations are not returned.
Overrides:
getAttribute in interface AbstractNode
Parameters:
name - The name of the attribute to retrieve.
Returns:
The Attr value as a string, or the empty string if that attribute does not have a specified or default value. (Note the difference from getAttributeValue(), which returns null if there is no value).

getAttributeList

public AttributeCollection getAttributeList()
Get the attribute list for this element.
Overrides:
getAttributeList in interface ElementImpl
Returns:
The attribute list. This will not include any namespace attributes. The attribute names will be in expanded form, with prefixes replaced by URIs

getAttributeNS

public String getAttributeNS(String namespaceURI,
                             String localName)
Retrieves an attribute value by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.
Overrides:
getAttributeNS in interface AbstractNode
Parameters:
namespaceURI - The namespace URI of the attribute to retrieve.
localName - The local name of the attribute to retrieve.
Returns:
The Attr value as a string, or the empty string if that attribute does not have a specified or default value.
Since:
DOM Level 2

getAttributeNode

public Attr getAttributeNode(String name)
Retrieves an attribute node by name. Namespace declarations are not returned.
To retrieve an attribute node by qualified name and namespace URI, use the getAttributeNodeNS method.
Overrides:
getAttributeNode in interface AbstractNode
Parameters:
name - The name (nodeName ) of the attribute to retrieve.
Returns:
The Attr node with the specified name ( nodeName ) or null if there is no such attribute.

getAttributeNodeNS

public Attr getAttributeNodeNS(String namespaceURI,
                               String localName)
Retrieves an Attr node by local name and namespace URI. DOM method, so namespace declarations count as attributes.
Overrides:
getAttributeNodeNS in interface AbstractNode
Parameters:
namespaceURI - The namespace URI of the attribute to retrieve.
localName - The local name of the attribute to retrieve.
Returns:
The Attr node with the specified attribute local name and namespace URI or null if there is no such attribute.
Since:
DOM Level 2

getAttributeValue

public String getAttributeValue(String name)
Find the value of a given attribute of this element.
This is a short-cut method; the full capability to examine attributes is offered via the getAttributeList() method.
The attribute may either be one that was present in the original XML document, or one that has been set by the application using setAttribute().
Overrides:
getAttributeValue in interface ElementImpl
Parameters:
name - the name of an attribute. There must be no prefix in the name.
Returns:
the value of the attribute, if it exists, otherwise null

getAttributeValue

public String getAttributeValue(String uri,
                                String localName)
Find the value of a given attribute of this node.
This method is defined on all nodes to meet XSL requirements, but for nodes other than elements it will always return null.
Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in interface NodeImpl
Parameters:
uri - the namespace uri of an attribute
localName - the local name of an attribute
Returns:
the value of the attribute, if it exists, otherwise null

getAttributeValue

public String getAttributeValue(int fingerprint)
Get the value of a given attribute of this node
Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in interface NodeImpl
Parameters:
fingerprint - The fingerprint of the attribute name
Returns:
the attribute value if it exists or null if not

getAttributes

public NamedNodeMap getAttributes()
A NamedNodeMap containing the attributes of this element. This is a DOM method, so the list of attributes includes namespace declarations.
Overrides:
getAttributes in interface NodeImpl

getLength

public int getLength()
Get number of attributes (DOM NamedNodeMap method). Treats namespace declarations as attributes.
Overrides:
getLength in interface AbstractNode

getNamedItem

public Node getNamedItem(String name)
Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.

getNamedItemNS

public Node getNamedItemNS(String uri,
                           String localName)
Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.

getNamespaceCodes

protected int[] getNamespaceCodes()
Get the list of in-scope namespaces for this element as an array of namespace codes. (Used by LiteralResultElement)

getPrefixForURI

public String getPrefixForURI(String uri)
Search the NamespaceList for a given URI, returning the corresponding prefix.
Overrides:
getPrefixForURI in interface ElementImpl
Parameters:
uri - The URI to be matched.
Returns:
The prefix corresponding to this URI. If not found, return null. If there is more than one prefix matching the URI, the first one found is returned. If the URI matches the default namespace, return an empty string.

getURICodeForPrefix

public short getURICodeForPrefix(String prefix)
            throws NamespaceException
Search the NamespaceList for a given prefix, returning the corresponding URI.
Overrides:
getURICodeForPrefix in interface ElementImpl
Parameters:
prefix - The prefix to be matched. To find the default namespace, supply ""
Returns:
The URI code corresponding to this namespace. If it is an unnamed default namespace, return Namespace.NULL_CODE.
Throws:
NamespaceException - if the prefix has not been declared on this NamespaceList.

hasAttribute

public boolean hasAttribute(String name)
Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise. Namespace declarations are not included.
Overrides:
hasAttribute in interface AbstractNode
Parameters:
name - The name of the attribute to look for.
Returns:
true if an attribute with the given name is specified on this element or has a default value, false otherwise.
Since:
DOM Level 2

hasAttributeNS

public boolean hasAttributeNS(String namespaceURI,
                              String localName)
Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise. This is a DOM method so namespace declarations are treated as attributes.
Overrides:
hasAttributeNS in interface AbstractNode
Parameters:
namespaceURI - The namespace URI of the attribute to look for.
localName - The local name of the attribute to look for.
Returns:
true if an attribute with the given local name and namespace URI is specified or has a default value on this element, false otherwise.
Since:
DOM Level 2

hasAttributes

public boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes.
Overrides:
hasAttributes in interface NodeImpl
Returns:
true if this node has any attributes, false otherwise.
Since:
DOM Level 2

initialise

public void initialise(int nameCode,
                       AttributeCollection atts,
                       NodeInfo parent,
                       String baseURI,
                       int lineNumber,
                       int sequenceNumber)
Initialise a new ElementWithAttributes with an element name and attribute list
Overrides:
initialise in interface ElementImpl
Parameters:
atts - The attribute list, after namespace processing
parent - The parent node

item

public Node item(int index)
Get n'th attribute (DOM NamedNodeMap method). Namespace declarations are not returned.

outputNamespaceNodes

public void outputNamespaceNodes(Outputter out,
                                 boolean includeAncestors)
            throws TransformerException
Output all namespace nodes associated with this element.
Specified by:
outputNamespaceNodes in interface NodeInfo
Overrides:
outputNamespaceNodes in interface ElementImpl
Parameters:
out - The relevant outputter

removeAttribute

public void removeAttribute(String name)
Removes an attribute by name.
Overrides:
removeAttribute in interface AbstractNode
Parameters:
name - The name of the attribute to remove.

removeAttributeNS

public void removeAttributeNS(String namespaceURI,
                              String localName)
            throws DOMException
Removes an attribute by local name and namespace URI. Always fails
Overrides:
removeAttributeNS in interface AbstractNode
Since:
DOM Level 2

removeAttributeNode

public Attr removeAttributeNode(Attr oldAttr)
            throws DOMException
Removes the specified attribute node. Always fails
Overrides:
removeAttributeNode in interface AbstractNode

removeNamedItem

public Node removeNamedItem(String name)
            throws DOMException
Remove named attribute (DOM NamedNodeMap method: always fails)

removeNamedItemNS

public Node removeNamedItemNS(String uri,
                              String localName)
            throws DOMException
Remove named attribute (DOM NamedNodeMap method: always fails)

setAttribute

public void setAttribute(String name,
                         String value)
            throws DOMException
Set the value of an attribute on the current element. This affects subsequent calls of getAttribute() for that element.
Overrides:
setAttribute in interface ElementImpl
Parameters:
name - The name of the attribute to be set. Any prefix is interpreted relative to the namespaces defined for this element.
value - The new value of the attribute. Set this to null to remove the attribute.

setAttributeNS

public void setAttributeNS(String namespaceURI,
                           String qualifiedName,
                           String value)
            throws DOMException
Adds a new attribute. Always fails.
Overrides:
setAttributeNS in interface AbstractNode
Parameters:
namespaceURI - The namespace URI of the attribute to create or alter.
qualifiedName - The qualified name of the attribute to create or alter.
value - The value to set in string form.

setAttributeNode

public Attr setAttributeNode(Attr newAttr)
            throws DOMException
Adds a new attribute node. Always fails
Overrides:
setAttributeNode in interface AbstractNode

setAttributeNodeNS

public Attr setAttributeNodeNS(Attr newAttr)
            throws DOMException
Add a new attribute. Always fails.
Overrides:
setAttributeNodeNS in interface AbstractNode
Parameters:
newAttr - The Attr node to add to the attribute list.
Returns:
If the newAttr attribute replaces an existing attribute with the same local name and namespace URI , the replaced Attr node is returned, otherwise null is returned.
Since:
DOM Level 2

setNamedItem

public Node setNamedItem(Node arg)
            throws DOMException
Set named attribute (DOM NamedNodeMap method: always fails)

setNamedItemNS

public Node setNamedItemNS(Node arg)
            throws DOMException
Set named attribute (DOM NamedNodeMap method: always fails)

setNamespaceDeclarations

public void setNamespaceDeclarations(int[] namespaces,
                                     int namespacesUsed)
Set the namespace declarations for the element