com.icl.saxon.tree
Class ElementWithAttributes

java.lang.Object
  |
  +--com.icl.saxon.tree.NodeImpl
        |
        +--com.icl.saxon.tree.ParentNodeImpl
              |
              +--com.icl.saxon.tree.ElementImpl
                    |
                    +--com.icl.saxon.tree.ElementWithAttributes
All Implemented Interfaces:
org.w3c.dom.Element, ElementInfo, org.w3c.dom.NamedNodeMap, org.w3c.dom.Node, NodeInfo
Direct Known Subclasses:
StyleElement

public class ElementWithAttributes
extends ElementImpl
implements ElementInfo, org.w3c.dom.Element, org.w3c.dom.NamedNodeMap

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

This class is an implementation of ElementInfo


Field Summary
protected  AttributeCollection attributeList
           
protected  java.lang.String[] namespaceList
           
 
Fields inherited from class com.icl.saxon.tree.ElementImpl
emptyArray, fullName, index, parent, sequence
 
Fields inherited from interface com.icl.saxon.om.NodeInfo
ATTRIBUTE, COMMENT, DOCUMENT, ELEMENT, NAMESPACE, NODE, NONE, NUMBER_OF_TYPES, PI, TEXT
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
ElementWithAttributes()
           
 
Method Summary
 void addNamespaceNodes(ElementInfo owner, java.util.Vector list, NodeInfo stop)
          Make the set of all namespace nodes associated with this element.
 void copy(Outputter out)
          Copy this node to a given outputter (supporting xsl:copy-of)
 java.lang.String getAttribute(java.lang.String name)
          Retrieves an attribute value by name.
 AttributeCollection getAttributeList()
          Get the attribute list for this element.
 org.w3c.dom.Attr getAttributeNode(java.lang.String name)
          Retrieves an attribute node by name.
 org.w3c.dom.Attr getAttributeNodeNS(java.lang.String namespaceURI, java.lang.String localName)
          Retrieves an Attr node by local name and namespace URI.
 java.lang.String getAttributeNS(java.lang.String namespaceURI, java.lang.String localName)
          Retrieves an attribute value by local name and namespace URI.
 org.w3c.dom.NamedNodeMap getAttributes()
          A NamedNodeMap containing the attributes of this element.
 java.lang.String getAttributeValue(Name name)
          Find the value of a given attribute of this element.
 java.lang.String getAttributeValue(java.lang.String name)
          Find the value of a given attribute of this element.
 int getLength()
          Get number of attributes (DOM NamedNodeMap method).
 org.w3c.dom.Node getNamedItem(java.lang.String name)
          Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.
 org.w3c.dom.Node getNamedItemNS(java.lang.String uri, java.lang.String localName)
          Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.
 java.lang.String getPrefixForURI(java.lang.String uri)
          Search the NamespaceList for a given URI, returning the corresponding prefix.
 java.lang.String getURIforPrefix(java.lang.String prefix)
          Search the NamespaceList for a given prefix, returning the corresponding URI.
 boolean hasAttribute(java.lang.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(java.lang.String namespaceURI, java.lang.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(Name name, AttributeCollection atts, NodeInfo parent, java.lang.String baseURI, int lineNumber, int sequenceNumber)
          Construct an empty ElementWithAttributes public ElementWithAttributes() {} /** Initialise a new ElementWithAttributes with an element name and attribute list
 org.w3c.dom.Node item(int index)
          Get n'th attribute (DOM NamedNodeMap method).
 AttributeInfo makeAttributeNode(Name attributeName)
          Make an attribute node for a given attribute of this element
 void outputNamespaceNodes(Outputter out)
          Output all namespace nodes associated with this element.
 void removeAttribute(java.lang.String name)
          Removes an attribute by name.
 org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
          Removes the specified attribute node.
 void removeAttributeNS(java.lang.String namespaceURI, java.lang.String localName)
          Removes an attribute by local name and namespace URI.
 org.w3c.dom.Node removeNamedItem(java.lang.String name)
          Remove named attribute (DOM NamedNodeMap method: always fails)
 org.w3c.dom.Node removeNamedItemNS(java.lang.String uri, java.lang.String localName)
          Remove named attribute (DOM NamedNodeMap method: always fails)
 void setAttribute(java.lang.String name, java.lang.String value)
          Set the value of an attribute on the current element.
 org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
          Adds a new attribute node.
 org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
          Add a new attribute.
 void setAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName, java.lang.String value)
          Adds a new attribute.
 org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg)
          Set named attribute (DOM NamedNodeMap method: always fails)
 org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg)
          Set named attribute (DOM NamedNodeMap method: always fails)
 void setNamespaceDeclarations(java.lang.String[] namespaces, int namespacesUsed)
          Set the namespace declarations to the element
 
Methods inherited from class com.icl.saxon.tree.ElementImpl
addChild, alphaKey, appendChild, cloneNode, compact, copyStringValue, defaultAction, disallowUpdate, dropChildren, getAbsoluteName, getAllChildNodes, getAncestor, getAncestor, getChildNodes, getColumnNumber, getDisplayName, getDocumentElement, getDocumentRoot, getElementsByTagName, getElementsByTagNameNS, getExpandedName, getFirstChild, getFirstChild, getIndex, getInheritedAttribute, getLastChild, getLastChild, getLineNumber, getLocalName, getNamespaceURI, getNextInDocument, getNextSibling, getNextSibling, getNodeName, getNodeType, getNodeTypeName, getNodeValue, getNthChild, getNumberAny, getNumberMulti, getNumberOfChildren, getNumberSimple, getNumberSimple, getNumberSingle, getOwnerDocument, getParentNode, getPath, getPrefix, getPreviousInDocument, getPreviousInDocument, getPreviousSibling, getPreviousSibling, getPublicId, getSequenceNumber, getSequentialKey, getSystemId, getTagName, getURI, getValue, hasChildNodes, hasName, insertBefore, isa, isAncestor, isDocumentElement, isFirstChild, isFirstInGroup, isLastChild, isLastInGroup, isSameNode, isSupported, makeName, makePrefixTest, normalize, removeChild, removeChild, removeNode, renumberChildren, replaceChild, setLineNumber, setNodeValue, setPrefix, supports, toString, useChildrenArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.icl.saxon.om.ElementInfo
getInheritedAttribute, isFirstChild, isFirstInGroup, isLastChild, isLastInGroup
 
Methods inherited from interface com.icl.saxon.om.NodeInfo
copyStringValue, defaultAction, getAbsoluteName, getAllChildNodes, getAncestor, getAncestor, getDisplayName, getDocumentElement, getDocumentRoot, getExpandedName, getFirstChild, getIndex, getLastChild, getLineNumber, getLocalName, getNextInDocument, getNextSibling, getNodeName, getNodeType, getNumberAny, getNumberMulti, getNumberOfChildren, getNumberSimple, getNumberSimple, getNumberSingle, getPath, getPrefix, getPreviousInDocument, getPreviousInDocument, getPreviousSibling, getSequenceNumber, getSequentialKey, getSystemId, getURI, getValue, hasName, isa, isAncestor, isDocumentElement, isSameNode
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, getChildNodes, getFirstChild, getLastChild, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 
Methods inherited from interface org.w3c.dom.Element
getElementsByTagName, getElementsByTagNameNS, getTagName
 

Field Detail

attributeList

protected AttributeCollection attributeList

namespaceList

protected java.lang.String[] namespaceList
Constructor Detail

ElementWithAttributes

public ElementWithAttributes()
Method Detail

initialise

public void initialise(Name name,
                       AttributeCollection atts,
                       NodeInfo parent,
                       java.lang.String baseURI,
                       int lineNumber,
                       int sequenceNumber)
                throws org.xml.sax.SAXException
Construct an empty ElementWithAttributes public ElementWithAttributes() {} /** Initialise a new ElementWithAttributes with an element name and attribute list
Overrides:
initialise in class ElementImpl
Parameters:
name - The element name, with namespaces resolved
atts - The attribute list, after namespace processing
parent - The parent node

setNamespaceDeclarations

public void setNamespaceDeclarations(java.lang.String[] namespaces,
                                     int namespacesUsed)
                              throws org.xml.sax.SAXException
Set the namespace declarations to the element

getURIforPrefix

public java.lang.String getURIforPrefix(java.lang.String prefix)
                                 throws org.xml.sax.SAXException
Search the NamespaceList for a given prefix, returning the corresponding URI.
Specified by:
getURIforPrefix in interface ElementInfo
Overrides:
getURIforPrefix in class ElementImpl
Parameters:
prefix - The prefix to be matched. To find the default namespace, supply ""
Returns:
The URI corresponding to this namespace. If it is an unnamed default namespace, return "".
Throws:
org.xml.sax.SAXException - if the prefix has not been declared on this NamespaceList.

getPrefixForURI

public java.lang.String getPrefixForURI(java.lang.String uri)
Search the NamespaceList for a given URI, returning the corresponding prefix.
Specified by:
getPrefixForURI in interface ElementInfo
Overrides:
getPrefixForURI in class 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.

addNamespaceNodes

public void addNamespaceNodes(ElementInfo owner,
                              java.util.Vector list,
                              NodeInfo stop)
                       throws org.xml.sax.SAXException
Make the set of all namespace nodes associated with this element.
Specified by:
addNamespaceNodes in interface ElementInfo
Overrides:
addNamespaceNodes in class ElementImpl
Parameters:
owner - The element owning these namespace nodes.
list - a Vector containing NamespaceInfo 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.
stop - the ancestor node to stop at. Supply null to go all the way back to the root node. [I believe all calls on this method now supply null: the functionality was provided for Literal Result Elements in the stylesheet but is no longer used].

outputNamespaceNodes

public void outputNamespaceNodes(Outputter out)
                          throws org.xml.sax.SAXException
Output all namespace nodes associated with this element.
Specified by:
outputNamespaceNodes in interface ElementInfo
Overrides:
outputNamespaceNodes in class ElementImpl
Parameters:
out - The relevant outputter

getAttributeList

public AttributeCollection getAttributeList()
Get the attribute list for this element.
Specified by:
getAttributeList in interface ElementInfo
Overrides:
getAttributeList in class 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

getAttributeValue

public java.lang.String getAttributeValue(Name 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().
Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in class ElementImpl
Parameters:
name - the name of an attribute. Any prefix in the name is interpreted in the context of the namespaces applying to the current element
Returns:
the value of the attribute, if it exists, otherwise null

getAttributeValue

public java.lang.String getAttributeValue(java.lang.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().
Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in class 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

makeAttributeNode

public AttributeInfo makeAttributeNode(Name attributeName)
Make an attribute node for a given attribute of this element
Specified by:
makeAttributeNode in interface ElementInfo
Overrides:
makeAttributeNode in class ElementImpl
Parameters:
name - The attribute name

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
                  throws org.w3c.dom.DOMException
Set the value of an attribute on the current element. This affects subsequent calls of getAttribute() for that element.
Specified by:
setAttribute in interface ElementInfo
Overrides:
setAttribute in class 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.

copy

public void copy(Outputter out)
          throws org.xml.sax.SAXException
Copy this node to a given outputter (supporting xsl:copy-of)
Specified by:
copy in interface NodeInfo
Overrides:
copy in class ElementImpl

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Retrieves an attribute value by name. This is a DOM method, so namespace declarations count as attributes.
Specified by:
getAttribute in interface org.w3c.dom.Element
Overrides:
getAttribute in class ElementImpl
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.

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()
A NamedNodeMap containing the attributes of this element. This is a DOM method, so the list of attributes includes namespace declarations.
Specified by:
getAttributes in interface org.w3c.dom.Node
Overrides:
getAttributes in class ElementImpl

removeAttribute

public void removeAttribute(java.lang.String name)
Removes an attribute by name.
Specified by:
removeAttribute in interface org.w3c.dom.Element
Overrides:
removeAttribute in class ElementImpl
Parameters:
name - The name of the attribute to remove.

getAttributeNode

public org.w3c.dom.Attr getAttributeNode(java.lang.String name)
Retrieves an attribute node by name. This is a DOM method, so namespace declarations are treated as attributes.
To retrieve an attribute node by qualified name and namespace URI, use the getAttributeNodeNS method.
Specified by:
getAttributeNode in interface org.w3c.dom.Element
Overrides:
getAttributeNode in class ElementImpl
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.

setAttributeNode

public org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
                                  throws org.w3c.dom.DOMException
Adds a new attribute node. Always fails
Specified by:
setAttributeNode in interface org.w3c.dom.Element
Overrides:
setAttributeNode in class ElementImpl
Throws:
org.w3c.dom.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

removeAttributeNode

public org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
                                     throws org.w3c.dom.DOMException
Removes the specified attribute node. Always fails
Specified by:
removeAttributeNode in interface org.w3c.dom.Element
Overrides:
removeAttributeNode in class ElementImpl
Throws:
org.w3c.dom.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

getAttributeNS

public java.lang.String getAttributeNS(java.lang.String namespaceURI,
                                       java.lang.String localName)
Retrieves an attribute value by local name and namespace URI. HTML-only DOM implementations do not need to implement this method.
Specified by:
getAttributeNS in interface org.w3c.dom.Element
Overrides:
getAttributeNS in class ElementImpl
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

setAttributeNS

public void setAttributeNS(java.lang.String namespaceURI,
                           java.lang.String qualifiedName,
                           java.lang.String value)
                    throws org.w3c.dom.DOMException
Adds a new attribute. Always fails.
Specified by:
setAttributeNS in interface org.w3c.dom.Element
Overrides:
setAttributeNS in class ElementImpl
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.
Throws:
org.w3c.dom.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

removeAttributeNS

public void removeAttributeNS(java.lang.String namespaceURI,
                              java.lang.String localName)
                       throws org.w3c.dom.DOMException
Removes an attribute by local name and namespace URI. Always fails
Specified by:
removeAttributeNS in interface org.w3c.dom.Element
Overrides:
removeAttributeNS in class ElementImpl
Throws:
org.w3c.dom.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Since:
DOM Level 2

getAttributeNodeNS

public org.w3c.dom.Attr getAttributeNodeNS(java.lang.String namespaceURI,
                                           java.lang.String localName)
Retrieves an Attr node by local name and namespace URI. DOM method, so namespace declarations count as attributes.
Specified by:
getAttributeNodeNS in interface org.w3c.dom.Element
Overrides:
getAttributeNodeNS in class ElementImpl
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

setAttributeNodeNS

public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
                                    throws org.w3c.dom.DOMException
Add a new attribute. Always fails.
Specified by:
setAttributeNodeNS in interface org.w3c.dom.Element
Overrides:
setAttributeNodeNS in class ElementImpl
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.
Throws:
org.w3c.dom.DOMException -
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Since:
DOM Level 2

hasAttributes

public boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes.
Specified by:
hasAttributes in interface org.w3c.dom.Node
Overrides:
hasAttributes in class com.icl.saxon.tree.NodeImpl
Returns:
true if this node has any attributes, false otherwise.
Since:
DOM Level 2

hasAttribute

public boolean hasAttribute(java.lang.String name)
Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise. This is a DOM method, so namespace declarations are treated as attributes.
Specified by:
hasAttribute in interface org.w3c.dom.Element
Overrides:
hasAttribute in class ElementImpl
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(java.lang.String namespaceURI,
                              java.lang.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.
Specified by:
hasAttributeNS in interface org.w3c.dom.Element
Overrides:
hasAttributeNS in class ElementImpl
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

getNamedItem

public org.w3c.dom.Node getNamedItem(java.lang.String name)
Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.
Specified by:
getNamedItem in interface org.w3c.dom.NamedNodeMap
Overrides:
getNamedItem in class ElementImpl

setNamedItem

public org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg)
                              throws org.w3c.dom.DOMException
Set named attribute (DOM NamedNodeMap method: always fails)
Specified by:
setNamedItem in interface org.w3c.dom.NamedNodeMap
Overrides:
setNamedItem in class ElementImpl

removeNamedItem

public org.w3c.dom.Node removeNamedItem(java.lang.String name)
                                 throws org.w3c.dom.DOMException
Remove named attribute (DOM NamedNodeMap method: always fails)
Specified by:
removeNamedItem in interface org.w3c.dom.NamedNodeMap
Overrides:
removeNamedItem in class ElementImpl

item

public org.w3c.dom.Node item(int index)
Get n'th attribute (DOM NamedNodeMap method). Namespace declarations are treated as attributes.
Specified by:
item in interface org.w3c.dom.NamedNodeMap
Overrides:
item in class ElementImpl

getLength

public int getLength()
Get number of attributes (DOM NamedNodeMap method). Treats namespace declarations as attributes.
Specified by:
getLength in interface org.w3c.dom.NamedNodeMap
Overrides:
getLength in class ElementImpl

getNamedItemNS

public org.w3c.dom.Node getNamedItemNS(java.lang.String uri,
                                       java.lang.String localName)
Get named attribute (DOM NamedNodeMap method) Treats namespace declarations as attributes.
Specified by:
getNamedItemNS in interface org.w3c.dom.NamedNodeMap
Overrides:
getNamedItemNS in class ElementImpl

setNamedItemNS

public org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg)
                                throws org.w3c.dom.DOMException
Set named attribute (DOM NamedNodeMap method: always fails)
Specified by:
setNamedItemNS in interface org.w3c.dom.NamedNodeMap
Overrides:
setNamedItemNS in class ElementImpl

removeNamedItemNS

public org.w3c.dom.Node removeNamedItemNS(java.lang.String uri,
                                          java.lang.String localName)
                                   throws org.w3c.dom.DOMException
Remove named attribute (DOM NamedNodeMap method: always fails)
Specified by:
removeNamedItemNS in interface org.w3c.dom.NamedNodeMap
Overrides:
removeNamedItemNS in class ElementImpl