Elements can have attributes, which are name="value" pairs that appear within the element start tag in an XML document; this class represents the in-memory representation of one of those attributes and can be used to examine or modify the name or value. More...
#include <Xml.h>
Public Member Functions | |
Attribute () | |
Default constructor creates a null Attribute handle. | |
Attribute (const String &name, const String &value) | |
Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element. | |
Attribute (const Attribute &src) | |
Copy constructor is shallow; that is, this handle will refer to the same attribute as the source. | |
Attribute & | operator= (const Attribute &src) |
Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source. | |
~Attribute () | |
Destructor will delete the referenced attribute if this handle is its owner, otherwise it will be left alone. | |
bool | isValid () const |
Is this handle currently holding an attribute? | |
const String & | getName () const |
If this is a valid attribute handle, get the name of the attribute. | |
const String & | getValue () const |
If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes. | |
Attribute & | setName (const String &name) |
If this is a valid attribute handle, change its name. | |
Attribute & | setValue (const String &value) |
If this is a valid attribute handle, change its value to the given String which should not be quoted. | |
void | clear () |
Clear this attribute handle; if the handle is the attribute's owner (that is, it isn't part of any element) then the attribute will be deleted, otherwise it is left unchanged. | |
void | writeToString (String &out) const |
Serialize this attribute to the given String. | |
bool | operator== (const Attribute &attr) const |
Comparison operators return true if the same attribute is being referenced or both handles are empty. | |
bool | operator!= (const Attribute &attr) const |
Friends | |
class | Xml::attribute_iterator |
class | Xml::Element |
Elements can have attributes, which are name="value" pairs that appear within the element start tag in an XML document; this class represents the in-memory representation of one of those attributes and can be used to examine or modify the name or value.
Attribute names within an element tag are unique.
Copy constructor is shallow; that is, this handle will refer to the same attribute as the source.
Note that this handle will provide write access to the underlying attribute, even if the source was const.
~Attribute | ( | ) | [inline] |
Destructor will delete the referenced attribute if this handle is its owner, otherwise it will be left alone.
void clear | ( | ) |
Clear this attribute handle; if the handle is the attribute's owner (that is, it isn't part of any element) then the attribute will be deleted, otherwise it is left unchanged.
const String& getName | ( | ) | const |
If this is a valid attribute handle, get the name of the attribute.
const String& getValue | ( | ) | const |
If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes.
Referenced by Element::getOptionalAttributeValue(), and Element::getOptionalAttributeValueAs().
bool isValid | ( | ) | const [inline] |
Is this handle currently holding an attribute?
Referenced by Element::getOptionalAttributeValue(), and Element::getOptionalAttributeValueAs().
bool operator!= | ( | const Attribute & | attr | ) | const [inline] |
Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source.
Note that this handle will provide write access to the underlying attribute even if the source handle was const.
bool operator== | ( | const Attribute & | attr | ) | const [inline] |
Comparison operators return true if the same attribute is being referenced or both handles are empty.
Note that two different attributes with the same properties will not test equal by this criterion.
If this is a valid attribute handle, change its name.
If this is a valid attribute handle, change its value to the given String which should not be quoted.
void writeToString | ( | String & | out | ) | const |
Serialize this attribute to the given String.
The output will be as it would appear in an XML file, i.e. name="value" or name='value' with special characters output as suitable entities. If you don't want it that way, use getName() and getValue() instead which return the raw strings.
friend class Xml::attribute_iterator [friend] |
friend class Xml::Element [friend] |