class Poco::XML::Attr

Overview

The Attr interface represents an attribute in an Element object. More…

#include <Attr.h>

class Attr: public Poco::XML::AbstractNode
{
public:
    // methods

    const XMLString&
    name() const;

    bool
    specified() const;

    const XMLString&
    value() const;

    const XMLString&
    getValue() const;

    void
    setValue(const XMLString& value);

    Element*
    ownerElement() const;

    virtual
    Node*
    parentNode() const;

    virtual
    const XMLString&
    nodeName() const;

    virtual
    const XMLString&
    getNodeValue() const;

    virtual
    void
    setNodeValue(const XMLString& value);

    virtual
    unsigned short
    nodeType() const;

    virtual
    Node*
    previousSibling() const;

    virtual
    const XMLString&
    namespaceURI() const;

    virtual
    XMLString
    prefix() const;

    virtual
    const XMLString&
    localName() const;

    virtual
    XMLString
    innerText() const;

protected:
    // construction

    Attr(
        Document* pOwnerDocument,
        Element* pOwnerElement,
        const XMLString& namespaceURI,
        const XMLString& localName,
        const XMLString& qname,
        const XMLString& value,
        bool specified = true
        );

    Attr(
        Document* pOwnerDocument,
        const Attr& attr
        );

    // methods

    virtual
    Node*
    copyNode(
        bool deep,
        Document* pOwnerDocument
        ) const;
};

Inherited Members

public:
    // typedefs

    typedef Poco::XML::NamespaceSupport NSMap;

    // enums

    enum
    {
        ELEMENT_NODE                = 1,
        ATTRIBUTE_NODE,
        TEXT_NODE,
        CDATA_SECTION_NODE,
        ENTITY_REFERENCE_NODE,
        ENTITY_NODE,
        PROCESSING_INSTRUCTION_NODE,
        COMMENT_NODE,
        DOCUMENT_NODE,
        DOCUMENT_TYPE_NODE,
        DOCUMENT_FRAGMENT_NODE,
        NOTATION_NODE,
    };

    // methods

    void
    duplicate() const;

    void
    release() const;

    virtual
    void
    autoRelease() = 0;

    virtual
    void
    addEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        ) = 0;

    virtual
    void
    removeEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        ) = 0;

    virtual
    bool
    dispatchEvent(Event* evt) = 0;

    virtual
    const XMLString&
    nodeName() const = 0;

    const XMLString&
    nodeValue() const;

    virtual
    const XMLString&
    getNodeValue() const = 0;

    virtual
    void
    setNodeValue(const XMLString& value) = 0;

    virtual
    unsigned short
    nodeType() const = 0;

    virtual
    Node*
    parentNode() const = 0;

    virtual
    NodeList*
    childNodes() const = 0;

    virtual
    Node*
    firstChild() const = 0;

    virtual
    Node*
    lastChild() const = 0;

    virtual
    Node*
    previousSibling() const = 0;

    virtual
    Node*
    nextSibling() const = 0;

    virtual
    NamedNodeMap*
    attributes() const = 0;

    virtual
    Document*
    ownerDocument() const = 0;

    virtual
    Node*
    insertBefore(
        Node* newChild,
        Node* refChild
        ) = 0;

    virtual
    Node*
    replaceChild(
        Node* newChild,
        Node* oldChild
        ) = 0;

    virtual
    Node*
    removeChild(Node* oldChild) = 0;

    virtual
    Node*
    appendChild(Node* newChild) = 0;

    virtual
    bool
    hasChildNodes() const = 0;

    virtual
    Node*
    cloneNode(bool deep) const = 0;

    virtual
    void
    normalize() = 0;

    virtual
    bool
    isSupported(
        const XMLString& feature,
        const XMLString& version
        ) const = 0;

    virtual
    const XMLString&
    namespaceURI() const = 0;

    virtual
    XMLString
    prefix() const = 0;

    virtual
    const XMLString&
    localName() const = 0;

    virtual
    bool
    hasAttributes() const = 0;

    virtual
    XMLString
    innerText() const = 0;

    virtual
    Node*
    getNodeByPath(const XMLString& path) const = 0;

    virtual
    Node*
    getNodeByPathNS(
        const XMLString& path,
        const NSMap& nsMap
        ) const = 0;

    virtual
    const XMLString&
    nodeName() const;

    virtual
    const XMLString&
    getNodeValue() const;

    virtual
    void
    setNodeValue(const XMLString& value);

    virtual
    Node*
    parentNode() const;

    virtual
    NodeList*
    childNodes() const;

    virtual
    Node*
    firstChild() const;

    virtual
    Node*
    lastChild() const;

    virtual
    Node*
    previousSibling() const;

    virtual
    Node*
    nextSibling() const;

    virtual
    NamedNodeMap*
    attributes() const;

    virtual
    Document*
    ownerDocument() const;

    virtual
    Node*
    insertBefore(
        Node* newChild,
        Node* refChild
        );

    virtual
    Node*
    replaceChild(
        Node* newChild,
        Node* oldChild
        );

    virtual
    Node*
    removeChild(Node* oldChild);

    virtual
    Node*
    appendChild(Node* newChild);

    virtual
    bool
    hasChildNodes() const;

    virtual
    Node*
    cloneNode(bool deep) const;

    virtual
    void
    normalize();

    virtual
    bool
    isSupported(
        const XMLString& feature,
        const XMLString& version
        ) const;

    virtual
    const XMLString&
    namespaceURI() const;

    virtual
    XMLString
    prefix() const;

    virtual
    const XMLString&
    localName() const;

    virtual
    bool
    hasAttributes() const;

    virtual
    void
    addEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        );

    virtual
    void
    removeEventListener(
        const XMLString& type,
        EventListener* listener,
        bool useCapture
        );

    virtual
    bool
    dispatchEvent(Event* evt);

    virtual
    XMLString
    innerText() const;

    virtual
    Node*
    getNodeByPath(const XMLString& path) const;

    virtual
    Node*
    getNodeByPathNS(
        const XMLString& path,
        const NSMap& nsMap
        ) const;

    virtual
    void
    autoRelease();

protected:
    // fields

    static const XMLString EMPTY_STRING;

    // methods

    virtual
    Node*
    copyNode(
        bool deep,
        Document* pOwnerDocument
        ) const = 0;

    virtual
    bool
    events() const;

    virtual
    bool
    eventsSuspended() const;

    void
    captureEvent(Event* evt);

    void
    bubbleEvent(Event* evt);

    void
    dispatchSubtreeModified();

    void
    dispatchNodeInserted();

    void
    dispatchNodeRemoved();

    virtual
    void
    dispatchNodeRemovedFromDocument();

    virtual
    void
    dispatchNodeInsertedIntoDocument();

    void
    dispatchAttrModified(
        Attr* pAttr,
        MutationEvent::AttrChangeType changeType,
        const XMLString& prevValue,
        const XMLString& newValue
        );

    void
    dispatchCharacterDataModified(
        const XMLString& prevValue,
        const XMLString& newValue
        );

    void
    setOwnerDocument(Document* pOwnerDocument);

Detailed Documentation

The Attr interface represents an attribute in an Element object.

Typically the allowable values for the attribute are defined in a document type definition.

Attr objects inherit the Node 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 Attr 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 DocumentFragment. However, they can be associated with Element nodes contained within a DocumentFragment. In short, users and implementors of the DOM need to be aware that Attr nodes have some things in common with other objects inheriting the Node interface, but they also are quite distinct.

The attribute’s effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attribute’s effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute’s effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that the nodeValue attribute on the Attr instance can also be used to retrieve the string version of the attribute’s value(s).

In XML, where the value of an attribute can contain entity references, the child nodes of the Attr node provide a representation in which entity references are not expanded. These child nodes may be either Text or EntityReference nodes. Because the attribute type may be unknown, there are no tokenized attribute values.

Methods

const XMLString&
name() const

Returns the name of this attribute.

bool
specified() const

If this attribute was explicitly given a value in the original document, this is true; otherwise, it is false.

Note that the implementation is in charge of this attribute, not the user. If the user changes the value of the attribute (even if it ends up having the same value as the default value) then the specified flag is automatically flipped to true. To re-specify the attribute as the default value from the DTD, the user must delete the attribute. The implementation will then make a new attribute available with specified set to false and the default value (if one exists). In summary:

* If the attribute has an assigned value in the document then specified
  is true, and the value is the assigned value.
* If the attribute has no assigned value in the document and has a default
  value in the DTD, then specified is false, and the value is the default
  value in the DTD.
* If the attribute has no assigned value in the document and has a value
  of #IMPLIED in the DTD, then the attribute does not appear in the structure
  model of the document.
* If the attribute is not associated to any element (i.e. because it
  was just created or was obtained from some removal or cloning operation)
  specified is true.
const XMLString&
value() const

Returns the value of the attribute as a string.

Character and general entity references are replaced with their values. See also the method getAttribute on the Element interface.

const XMLString&
getValue() const

Returns the value of the attribute as a string.

Character and general entity references are replaced with their values. See also the method getAttribute on the Element interface.

void
setValue(const XMLString& value)

Sets the value of the attribute as a string.

This creates a Text node with the unparsed contents of the string. I.e. any characters that an XML processor would recognize as markup are instead treated as literal text. See also the method setAttribute on the Element interface.

Element*
ownerElement() const

The Element node this attribute is attached to or null if this attribute is not in use.

virtual
Node*
parentNode() const

The parent of this node.

All nodes, except Attr, Document, DocumentFragment, Entity, and Notation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.

virtual
const XMLString&
nodeName() const

Returns the name of this node, depending on its type.

virtual
const XMLString&
getNodeValue() const

Returns the value of this node, depending on its type.

virtual
void
setNodeValue(const XMLString& value)

Sets the value of this node.

Throws an exception if the node is read-only.

virtual
unsigned short
nodeType() const

Returns a code representing the type of the underlying object.

virtual
Node*
previousSibling() const

Returns the node immediately preceding this node.

If there is no such node, this returns null.

virtual
const XMLString&
namespaceURI() const

Returns the namespace URI of the node.

This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.

For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always the empty string.

virtual
XMLString
prefix() const

Returns the namespace prefix from the qualified name of the node.

virtual
const XMLString&
localName() const

Returns the local name of the node.

virtual
XMLString
innerText() const

Returns a string containing the concatenated values of the node and all its child nodes.

This method is not part of the W3C Document Object Model.