gnu.xml.dom

Class DomAttr

Implemented Interfaces:
Attr, Cloneable, Comparable<T>, DocumentEvent, EventTarget, Node, NodeList

public class DomAttr
extends DomNsNode
implements Attr

"Attr" implementation. In DOM, attributes cost quite a lot of memory because their values are complex structures rather than just simple strings. To reduce your costs, avoid having more than one child of an attribute; stick to a single Text node child, and ignore even that by using the attribute's "nodeValue" property.

As a bit of general advice, only look at attribute modification events through the DOMAttrModified event (sent to the associated element). Implementations are not guaranteed to report other events in the same order, so you're very likely to write nonportable code if you monitor events at the "children of Attr" level.

At this writing, not all attribute modifications will cause the DOMAttrModified event to be triggered ... only the ones using the string methods (setNodeValue, setValue, and Element.setAttribute) to modify those values. That is, if you manipulate those children directly, elements won't get notified that attribute values have changed. The natural fix for that will report other modifications, but won't be able to expose "previous" attribute value; it'll need to be cached or something (at which point why bother using child nodes).

You are strongly advised not to use "children" of any attribute nodes you work with.

Fields inherited from interface org.w3c.dom.Node

ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE

Constructor Summary

DomAttr(DomDocument owner, String namespaceURI, String name)
Constructs an Attr node associated with the specified document.
DomAttr(DomDocument owner, String namespaceURI, String name, String prefix, String localName)
Constructs an Attr node associated with the specified document.

Method Summary

Object
clone()
Shallow clone of the attribute, breaking all ties with any elements.
String
getBaseURI()
The base URI of an Attr is always null.
Node
getFirstChild()
DOM L1 Returns the first child of this node, or null if there are none.
Node
getLastChild()
DOM L1 Returns the last child of this node, or null if there are none.
String
getName()
DOM L1 Returns the attribute name (same as getNodeName)
Node
getNextSibling()
DOM L1 Returns the previous sibling, if one is known.
String
getNodeValue()
DOM L1 Returns the attribute value, with character and entity references substituted.
Element
getOwnerElement()
DOM L2 Returns the element with which this attribute is associated.
Node
getParentNode()
DOM L1 Returns the parent node, if one is known.
Node
getPreviousSibling()
DOM L1 Returns the previous sibling, if one is known.
TypeInfo
getSchemaTypeInfo()
The type information associated with this attribute.
boolean
getSpecified()
DOM L1 Returns true if a parser reported this was in the source text.
String
getValue()
DOM L1 Returns the value of the attribute as a non-null string; same as getNodeValue.
boolean
isId()
Returns whether this attribute is known to be of type ID (i.e. to contain an identifier for its owner element) or not.
Node
item(int index)
DOM L1 (NodeList) Returns the item with the specified index in this NodeList, else null.
void
setNodeValue(String value)
DOM L1 Assigns the attribute value; using this API, no entity or character references will exist.
void
setOwnerElement(Element e)
Records the element with which this attribute is associated.
void
setSpecified(boolean value)
Records whether this attribute was in the source text.
void
setValue(String value)
DOM L1 Assigns the value of the attribute; it will have one child, which is a text node with the specified value (same as setNodeValue).

Methods inherited from class gnu.xml.dom.DomNsNode

getLocalName, getNamespaceURI, getNodeName, getPrefix, setPrefix

Methods inherited from class gnu.xml.dom.DomNode

addEventListener, appendChild, clone, cloneNode, compact, compareDocumentPosition, compareTo, createEvent, dispatchEvent, getAttributes, getBaseURI, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFeature, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isReadonly, isSameNode, isSupported, item, list, lookupNamespaceURI, lookupPrefix, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData, toString, trimToSize

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DomAttr

protected DomAttr(DomDocument owner,
                  String namespaceURI,
                  String name)
Constructs an Attr node associated with the specified document. The "specified" flag is initialized to true, since this DOM has no current "back door" mechanisms to manage default values so that every value must effectively be "specified".

This constructor should only be invoked by a Document as part of its createAttribute functionality, or through a subclass which is similarly used in a "Sub-DOM" style layer.

Parameters:
owner - The document with which this node is associated
namespaceURI - Combined with the local part of the name, this is used to uniquely identify a type of attribute
name - Name of this attribute, which may include a prefix

DomAttr

protected DomAttr(DomDocument owner,
                  String namespaceURI,
                  String name,
                  String prefix,
                  String localName)
Constructs an Attr node associated with the specified document. The "specified" flag is initialized to true, since this DOM has no current "back door" mechanisms to manage default values so that every value must effectively be "specified".

This constructor should only be invoked by a Document as part of its createAttribute functionality, or through a subclass which is similarly used in a "Sub-DOM" style layer.

With this constructor, the prefix and local part are given explicitly rather than being computed. This allows them to be explicitly set to null as required by Document.createAttribute(String).

Parameters:
owner - The document with which this node is associated
namespaceURI - Combined with the local part of the name, this is used to uniquely identify a type of attribute
name - Name of this attribute, which may include a prefix
prefix - the namespace prefix of the name. May be null.
localName - the local part of the name. May be null.

Method Details

clone

public Object clone()
Shallow clone of the attribute, breaking all ties with any elements.
Overrides:
clone in interface DomNode

getBaseURI

public final String getBaseURI()
The base URI of an Attr is always null.
Specified by:
getBaseURI in interface Node
Overrides:
getBaseURI in interface DomNode

getFirstChild

public final Node getFirstChild()
DOM L1 Returns the first child of this node, or null if there are none.
Specified by:
getFirstChild in interface Node
Overrides:
getFirstChild in interface DomNode

getLastChild

public final Node getLastChild()
DOM L1 Returns the last child of this node, or null if there are none.
Specified by:
getLastChild in interface Node
Overrides:
getLastChild in interface DomNode

getName

public final String getName()
DOM L1 Returns the attribute name (same as getNodeName)
Specified by:
getName in interface Attr

getNextSibling

public final Node getNextSibling()
DOM L1 Returns the previous sibling, if one is known.
Specified by:
getNextSibling in interface Node
Overrides:
getNextSibling in interface DomNode

getNodeValue

public String getNodeValue()
DOM L1 Returns the attribute value, with character and entity references substituted. NOTE: entity refs as children aren't currently handled.
Specified by:
getNodeValue in interface Node
Overrides:
getNodeValue in interface DomNode

getOwnerElement

public final Element getOwnerElement()
DOM L2 Returns the element with which this attribute is associated.
Specified by:
getOwnerElement in interface Attr

getParentNode

public Node getParentNode()
DOM L1 Returns the parent node, if one is known.
Specified by:
getParentNode in interface Node
Overrides:
getParentNode in interface DomNode

getPreviousSibling

public final Node getPreviousSibling()
DOM L1 Returns the previous sibling, if one is known.
Specified by:
getPreviousSibling in interface Node
Overrides:
getPreviousSibling in interface DomNode

getSchemaTypeInfo

public TypeInfo getSchemaTypeInfo()
The type information associated with this attribute. While the type information contained in this attribute is guarantee to be correct after loading the document or invoking Document.normalizeDocument(), schemaTypeInfo may not be reliable if the node was moved.
Specified by:
getSchemaTypeInfo in interface Attr
Since:
DOM Level 3

getSpecified

public final boolean getSpecified()
DOM L1 Returns true if a parser reported this was in the source text.
Specified by:
getSpecified in interface Attr

getValue

public final String getValue()
DOM L1 Returns the value of the attribute as a non-null string; same as getNodeValue. NOTE: entity refs as children aren't currently handled.
Specified by:
getValue in interface Attr

isId

public boolean isId()
Returns whether this attribute is known to be of type ID (i.e. to contain an identifier for its owner element) or not. When it is and its value is unique, the ownerElement of this attribute can be retrieved using the method Document.getElementById . The implementation could use several ways to determine if an attribute node is known to contain an identifier:
  • If validation occurred using an XML Schema [XML Schema Part 1] while loading the document or while invoking Document.normalizeDocument(), the post-schema-validation infoset contributions (PSVI contributions) values are used to determine if this attribute is a schema-determined ID attribute using the schema-determined ID definition in [XPointer] .
  • If validation occurred using a DTD while loading the document or while invoking Document.normalizeDocument(), the infoset [type definition] value is used to determine if this attribute is a DTD-determined ID attribute using the DTD-determined ID definition in [XPointer] .
  • from the use of the methods Element.setIdAttribute(), Element.setIdAttributeNS(), or Element.setIdAttributeNode(), i.e. it is an user-determined ID attribute;

    Note: XPointer framework (see section 3.2 in [XPointer] ) consider the DOM user-determined ID attribute as being part of the XPointer externally-determined ID definition.

  • using mechanisms that are outside the scope of this specification, it is then an externally-determined ID attribute. This includes using schema languages different from XML schema and DTD.

If validation occurred while invoking Document.normalizeDocument(), all user-determined ID attributes are reset and all attribute nodes ID information are then reevaluated in accordance to the schema used. As a consequence, if the Attr.schemaTypeInfo attribute contains an ID type, isId will always return true.
Specified by:
isId in interface Attr
Since:
DOM Level 3

item

public Node item(int index)
DOM L1 (NodeList) Returns the item with the specified index in this NodeList, else null.
Specified by:
item in interface NodeList
Overrides:
item in interface DomNode

setNodeValue

public void setNodeValue(String value)
DOM L1 Assigns the attribute value; using this API, no entity or character references will exist. Causes a DOMAttrModified mutation event to be sent.
Specified by:
setNodeValue in interface Node
Overrides:
setNodeValue in interface DomNode

setOwnerElement

public final void setOwnerElement(Element e)
Records the element with which this attribute is associated.

setSpecified

public final void setSpecified(boolean value)
Records whether this attribute was in the source text.

setValue

public final void setValue(String value)
DOM L1 Assigns the value of the attribute; it will have one child, which is a text node with the specified value (same as setNodeValue).
Specified by:
setValue in interface Attr

DomAttr.java -- Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.