root / Community Core Vision / Windows / libs / poco / include / Poco / DOM / Attr.h @ 8

View | Annotate | Download (7.6 KB)

1
//
2
// Attr.h
3
//
4
// $Id: //poco/1.3/XML/include/Poco/DOM/Attr.h#1 $
5
//
6
// Library: XML
7
// Package: DOM
8
// Module:  DOM
9
//
10
// Definition of the DOM Attr class.
11
//
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13
// and Contributors.
14
//
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
21
// 
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
28
// 
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
36
//
37
38
39
#ifndef DOM_Attr_INCLUDED
40
#define DOM_Attr_INCLUDED
41
42
43
#include "Poco/XML/XML.h"
44
#include "Poco/DOM/AbstractNode.h"
45
#include "Poco/DOM/Element.h"
46
#include "Poco/XML/Name.h"
47
48
49
namespace Poco {
50
namespace XML {
51
52
53
class XML_API Attr: public AbstractNode
54
        /// The Attr interface represents an attribute in an Element object. Typically
55
        /// the allowable values for the attribute are defined in a document type definition.
56
        /// 
57
        /// Attr objects inherit the Node interface, but since they are not actually
58
        /// child nodes of the element they describe, the DOM does not consider them
59
        /// part of the document tree. Thus, the Node attributes parentNode, previousSibling,
60
        /// and nextSibling have a null value for Attr objects. The DOM takes the view
61
        /// that attributes are properties of elements rather than having a separate
62
        /// identity from the elements they are associated with; this should make it
63
        /// more efficient to implement such features as default attributes associated
64
        /// with all elements of a given type. Furthermore, Attr nodes may not be immediate
65
        /// children of a DocumentFragment. However, they can be associated with Element
66
        /// nodes contained within a DocumentFragment. In short, users and implementors
67
        /// of the DOM need to be aware that Attr nodes have some things in common with
68
        /// other objects inheriting the Node interface, but they also are quite distinct.
69
        /// 
70
        /// The attribute's effective value is determined as follows: if this attribute
71
        /// has been explicitly assigned any value, that value is the attribute's effective
72
        /// value; otherwise, if there is a declaration for this attribute, and that
73
        /// declaration includes a default value, then that default value is the attribute's
74
        /// effective value; otherwise, the attribute does not exist on this element
75
        /// in the structure model until it has been explicitly added. Note that the
76
        /// nodeValue attribute on the Attr instance can also be used to retrieve the
77
        /// string version of the attribute's value(s).
78
        /// 
79
        /// In XML, where the value of an attribute can contain entity references, the
80
        /// child nodes of the Attr node provide a representation in which entity references
81
        /// are not expanded. These child nodes may be either Text or EntityReference
82
        /// nodes. Because the attribute type may be unknown, there are no tokenized
83
        /// attribute values.
84
{
85
public:
86
        const XMLString& name() const;
87
                /// Returns the name of this attribute.
88
89
        bool specified() const;
90
                /// If this attribute was explicitly given a value in the original document,
91
                /// this is true; otherwise, it is false. Note that the implementation is in
92
                /// charge of this attribute, not the user. If the user changes the value of
93
                /// the attribute (even if it ends up having the same value as the default value)
94
                /// then the specified flag is automatically flipped to true. To re-specify
95
                /// the attribute as the default value from the DTD, the user must delete the
96
                /// attribute. The implementation will then make a new attribute available with
97
                /// specified set to false and the default value (if one exists).
98
                /// In summary:
99
                /// 
100
                ///     * If the attribute has an assigned value in the document then specified
101
                ///       is true, and the value is the assigned value.
102
                ///     * If the attribute has no assigned value in the document and has a default
103
                ///       value in the DTD, then specified is false, and the value is the default
104
                ///       value in the DTD.
105
                ///     * If the attribute has no assigned value in the document and has a value
106
                ///       of #IMPLIED in the DTD, then the attribute does not appear in the structure
107
                ///       model of the document.
108
                ///     * If the attribute is not associated to any element (i.e. because it
109
                ///       was just created or was obtained from some removal or cloning operation)
110
                ///       specified is true.
111
112
        const XMLString& value() const;
113
                /// Returns the value of the attribute as a string. Character
114
                /// and general entity references are replaced with their values. See also the
115
                /// method getAttribute on the Element interface.
116
117
        const XMLString& getValue() const;
118
                /// Returns the value of the attribute as a string. Character
119
                /// and general entity references are replaced with their values. See also the
120
                /// method getAttribute on the Element interface.
121
122
        void setValue(const XMLString& value);
123
                /// Sets the value of the attribute as a string.
124
                /// This creates a Text node with the unparsed contents of the string.
125
                /// I.e. any characters that an XML processor would recognize as markup are
126
                /// instead treated as literal text. See also the method setAttribute on the
127
                /// Element interface.
128
129
        // DOM Level 2
130
        Element* ownerElement() const;
131
                /// The Element node this attribute is attached to or null 
132
                /// if this attribute is not in use.
133
134
        // Node
135
        Node* parentNode() const;
136
        const XMLString& nodeName() const;
137
        const XMLString& getNodeValue() const;
138
        void setNodeValue(const XMLString& value);
139
        unsigned short nodeType() const;
140
        Node* previousSibling() const;
141
        const XMLString& namespaceURI() const;
142
        XMLString prefix() const;
143
        const XMLString& localName() const;
144
145
        // Non-standard extensions
146
        XMLString innerText() const;
147
148
protected:
149
        Attr(Document* pOwnerDocument, Element* pOwnerElement, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified = true);
150
        Attr(Document* pOwnerDocument, const Attr& attr);
151
        ~Attr();
152
        
153
        Node* copyNode(bool deep, Document* pOwnerDocument) const;
154
155
private:
156
        const Name& _name;
157
        XMLString   _value;
158
        bool        _specified;
159
160
        friend class Document;
161
        friend class Element;
162
        friend class DOMBuilder;
163
};
164
165
166
//
167
// inlines
168
//
169
inline const XMLString& Attr::name() const
170
{
171
        return _name.qname();
172
}
173
174
175
inline const XMLString& Attr::value() const
176
{
177
        return _value;
178
}
179
180
181
inline const XMLString& Attr::getValue() const
182
{
183
        return _value;
184
}
185
186
187
inline bool Attr::specified() const
188
{
189
        return _specified;
190
}
191
192
193
inline Element* Attr::ownerElement() const
194
{
195
        return static_cast<Element*>(_pParent);
196
}
197
198
199
} } // namespace Poco::XML
200
201
202
#endif // DOM_Attr_INCLUDED