#include <DomAttribute.h>
Inherits xmldom::DomNode.
Inheritance diagram for xmldom::DomAttribute:
DomElement
object.
Typically the allowable values for the attribute are defined in a schema associated with the document. DomAttribute objects inherit the DomNode
interface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree. Thus, the Node attributes parentNode()
, previousSibling()
, and nextSibling()
have a null value for DomAttribute objects. The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with; this should make it more efficient to implement such features as default attributes associated with all elements of a given type.
Furthermore, Attr nodes may not be immediate children of a DomDocumentFragment
. However, they can be associated with DomElement
nodes contained within a DomDocumentFragment
. In short, users and implementors of the DOM need to be aware that DomAttribute nodes have some things in common with other objects inheriting the Node interface, but they also are quite distinct.
The attributes effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attributes effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attributes effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that the DomNode.nodeValue()
attribute on the DomAttribute instance can also be used to retrieve the string version of the attributes value(s).
If the attribute was not explicitly given a value in the instance document but has a default value provided by the schema associated with the document, an attribute node will be created with specified set to false. Removing attribute nodes for which a default value is defined in the schema generates a new attribute node with the default value and specified set to false. If validation occurred while invoking Document.normalizeDocument()
, attribute nodes with specified equals to false are recomputed according to the default attribute values provided by the schema. If no default value is associate with this attribute in the schema, the attribute node is discarded.
In XML, where the value of an attribute can contain entity references, the child nodes of the DomAttribute node may be either DomText
or DomEntityReference
nodes (when these are in use; see the description of EntityReference for discussion).
The DOM Core represents all attribute values as simple strings, even if the DTD or schema associated with the document declares them of some specific type such as tokenized.
The way attribute value normalization is performed by the DOM implementation depends on how much the implementation knows about the schema in use. Typically, the getValue()
and getNodeValue()
attributes of an DomAttribute
node initially returns the normalized value given by the parser. It is also the case after Document.normalizeDocument()
is called (assuming the right options have been set). But this may not be the case after mutation, independently of whether the mutation is performed by setting the string value directly or by changing the DomAttribute child nodes. In particular, this is true when character references are involved, given that they are not represented in the DOM and they impact attribute value normalization. On the other hand, if the implementation knows about the schema in use when the attribute value is changed, and it is of a different type than CDATA, it may normalize it again at that time. This is especially true of specialized DOM implementations, such as SVG DOM implementations, which store attribute values in an internal form different from a string.
Public Member Functions | |
DomAttribute () | |
ctor | |
DomAttribute (const DomAttribute ©) | |
copy ctor | |
virtual | ~DomAttribute () |
dtor | |
const DomAttribute & | operator= (const DomAttribute &assign) |
assign | |
DOM Level 1 | |
DomString | getName () const |
Returns the name of this attribute. | |
bool | getSpecified () const |
Returns true if the attribute received its value explicitly in the XML document, or if a value was assigned programatically with the setValue function. | |
DomString | getValue () const |
Returns the value of the attribute. | |
void | setValue (const DomString &value) |
Sets the value of the attribute. | |
DOM Level 2 | |
DomElement | getOwnerElement () const |
The DomElement node this attribute is attached to or null if this attribute is not in use. | |
DOM Level 3 | |
bool | isId () const |
Returns whether this attribute is known to be of type ID or not. |
xmldom::DomAttribute::DomAttribute | ( | ) |
ctor
xmldom::DomAttribute::DomAttribute | ( | const DomAttribute & | copy | ) |
copy ctor
xmldom::DomAttribute::~DomAttribute | ( | ) | [virtual] |
dtor
const DomAttribute & xmldom::DomAttribute::operator= | ( | const DomAttribute & | assign | ) |
assign
DomString xmldom::DomAttribute::getName | ( | ) | const |
Returns the name of this attribute.
bool xmldom::DomAttribute::getSpecified | ( | ) | const |
Returns true if the attribute received its value explicitly in the XML document, or if a value was assigned programatically with the setValue function.
Returns false if the attribute value came from the default value declared in the document's DTD.
DomString xmldom::DomAttribute::getValue | ( | ) | const |
Returns the value of the attribute.
The value of the attribute is returned as a string. Character and general entity references are replaced with their values.
void xmldom::DomAttribute::setValue | ( | const DomString & | value | ) |
Sets the value of the attribute.
A text node with the unparsed contents of the string will be created.
DomElement xmldom::DomAttribute::getOwnerElement | ( | ) | const |
The DomElement
node this attribute is attached to or null if this attribute is not in use.
bool xmldom::DomAttribute::isId | ( | ) | const |
Returns whether this attribute is known to be of type ID or not.
When it is and its value is unique, the ownerElement of this attribute can be retrieved using getElementById
on DomDocument
.