libcommonc++
0.7
|
An object representing an XML element. More...
#include <XMLElement.h++>
Public Member Functions | |
String | getName () const |
Get the name of the element. More... | |
void | setAttribute (const String &name, const String &value) |
Set a String attribute in the element. More... | |
void | setAttribute (const String &name, int value) |
Set an integer attribute in the element. More... | |
void | setAttribute (const String &name, const int64_t &value) |
Set a 64-bit integer attribute in the element. More... | |
void | setAttribute (const String &name, const double &value) |
Set a floating point attribute in the element. More... | |
void | setAttribute (const String &name, bool value) |
Set a boolean attribute in the element. More... | |
XMLElement & | getParent () |
Get the parent element of this element. More... | |
const XMLElement & | getParent () const |
Get the parent element of this element. More... | |
bool | getAttribute (const String &name, String &value, const String &defaultValue="") const |
Get the value of a String attribute in the element. More... | |
bool | getAttribute (const String &name, int &value, int defaultValue=0) const |
Get the value of an integer attribute in the element. More... | |
bool | getAttribute (const String &name, int64_t &value, const int64_t &defaultValue=0) const |
Get the value of a 64-bit integer attribute in the element. More... | |
bool | getAttribute (const String &name, bool &value, bool defaultValue=false) const |
Get the value of a boolean attribute in the element. More... | |
bool | getAttribute (const String &name, double &value, const double &defaultValue=0.0) const |
Get the value of a floating point attribute in the element. More... | |
void | getAttributeNames (StringVec &names) const |
Get the names of all of the element's attributes. More... | |
void | removeAttributes () |
Remove all attributes from the element. More... | |
bool | hasAttributes () const |
Test if the element has any attributes. More... | |
bool | hasContent () const |
Test if the element has content. More... | |
void | setContent (const String &content) |
Set the element's content. More... | |
const String | getContent () const |
Get the element's content. More... | |
bool | hasChildren () const |
Test if the element has children. More... | |
uint_t | getChildCount () const |
Get the element's child count. More... | |
XMLElement & | addChild (const String &name) |
Add a new child element to the element. More... | |
XMLElement & | getChild (const String &name=String::null) |
Get the first child of the element. More... | |
const XMLElement & | getChild (const String &name=String::null) const |
Get the first child of the element. More... | |
XMLElement & | getChild (uint_t index) |
Get the child at the given index. More... | |
const XMLElement & | getChild (uint_t index) const |
Get the child at the given index. More... | |
bool | hasChild (const String &name) const |
Test if the element has at least one child element with the given name. More... | |
XMLElement & | operator[] (const String &name) |
Get the first child with the given name. More... | |
XMLElement & | operator[] (const char *name) |
Get the first child with the given name. More... | |
const XMLElement & | operator[] (const String &name) const |
Get the first child with the given name. More... | |
const XMLElement & | operator[] (const char *name) const |
Get the first child with the given name. More... | |
XMLElement & | operator[] (int index) |
Get the child at the given index. More... | |
const XMLElement & | operator[] (int index) const |
Get the child at the given index. More... | |
void | removeChildren () |
Remove (and delete) all of the child elements. More... | |
void | removeChildren (const String &name) |
Remove (and delete) all of the child elements with the given name. More... | |
XMLElement & | operator= (bool val) |
Set the element's content to the string representation of a bool. More... | |
XMLElement & | operator= (long val) |
Set the element's content to the string representation of a long. More... | |
XMLElement & | operator= (unsigned long val) |
Set the element's content to the string representation of an unsigned long. More... | |
XMLElement & | operator= (const int64_t &val) |
Set the element's content to the string representation of an int64_t. More... | |
XMLElement & | operator= (const uint64_t &val) |
Set the element's content to the string representation of a uint64_t. More... | |
XMLElement & | operator= (float val) |
Set the element's content to the string representation of a float. More... | |
XMLElement & | operator= (const double &val) |
Set the element's content to the string representation of a double. More... | |
XMLElement & | operator= (const String &val) |
Set the element's content. More... | |
bool | toBool () const |
Return the element's content as a bool. More... | |
int | toInt () const |
Return the element's content as a long. More... | |
uint_t | toUInt () const |
Return the element's content as an unsigned long. More... | |
int64_t | toInt64 () const |
Return the element's content as an int64_t. More... | |
uint64_t | toUInt64 () const |
Return the element's content as a uint64_t. More... | |
float | toFloat () const |
Return the element's content as a float. More... | |
double | toDouble () const |
Return the element's content as a double. More... | |
String | toString () const |
Return the element's content as a String. More... | |
bool | isNull () const |
Test if the element is a "null" element. More... | |
operator const void * () const | |
Boolean evaluation cast operator. More... | |
bool | operator! () const |
Test if the element is a "null" element. More... | |
void | write (std::ostream &stream, int depth, uint_t tabWidth) const |
Write the element (and its children, recursively) to a stream. More... | |
Static Public Member Functions | |
static void | validateName (const String &name) |
Determine if an element or attribute name is valid. More... | |
Static Public Attributes | |
static XMLElement | null |
The "null" element. More... | |
Friends | |
class | XMLDocument |
class | XMLElementConstIterator |
class | XMLElementIterator |
An object representing an XML element.
XMLElement objects cannot be constructed directly by the caller, to reinforce the convention that they are owned by their enclosing XMLDocument.
All methods in this class return XMLElement::null if a matching or requested element was not found; this is a special instance of XMLElement for which isNull() returns true and whose mutator methods are all no-ops.
To iterate over the child elements of a given element elem
, use an XMLElementIterator or XMLElementConstIterator.
XMLElement & addChild | ( | const String & | name | ) |
Add a new child element to the element.
name | The name for the new element. |
InvalidArgumentException | If the name is invalid. |
Get the value of a String attribute in the element.
name | The attribute name. |
value | The value to fill in. |
defaultValue | The value to fill in if the element has no attribute with the given name. |
InvalidArgumentException | If the name is invalid. |
bool getAttribute | ( | const String & | name, |
int & | value, | ||
int | defaultValue = 0 |
||
) | const |
Get the value of an integer attribute in the element.
name | The attribute name. |
value | The value to fill in. |
defaultValue | The value to fill in if the element has no attribute with the given name. |
InvalidArgumentException | If the name is invalid. |
bool getAttribute | ( | const String & | name, |
int64_t & | value, | ||
const int64_t & | defaultValue = 0 |
||
) | const |
Get the value of a 64-bit integer attribute in the element.
name | The attribute name. |
value | The value to fill in. |
defaultValue | The value to fill in if the element has no attribute with the given name. |
InvalidArgumentException | If the name is invalid. |
bool getAttribute | ( | const String & | name, |
bool & | value, | ||
bool | defaultValue = false |
||
) | const |
Get the value of a boolean attribute in the element.
name | The attribute name. |
value | The value to fill in. |
defaultValue | The value to fill in if the element has no attribute with the given name. |
InvalidArgumentException | If the name is invalid. |
bool getAttribute | ( | const String & | name, |
double & | value, | ||
const double & | defaultValue = 0.0 |
||
) | const |
Get the value of a floating point attribute in the element.
name | The attribute name. |
value | The value to fill in. |
defaultValue | The value to fill in if the element has no attribute with the given name. |
InvalidArgumentException | If the name is invalid. |
void getAttributeNames | ( | StringVec & | names | ) | const |
Get the names of all of the element's attributes.
names | The vector in which to place the names. |
XMLElement & getChild | ( | const String & | name = String::null | ) |
Get the first child of the element.
name | If not String::null, gets the firt child element with the given name. |
const XMLElement & getChild | ( | const String & | name = String::null | ) | const |
Get the first child of the element.
name | If not String::null, gets the firt child element with the given name. |
XMLElement & getChild | ( | uint_t | index | ) |
Get the child at the given index.
index | The index. |
const XMLElement & getChild | ( | uint_t | index | ) | const |
Get the child at the given index.
index | The index. |
uint_t getChildCount | ( | ) | const |
Get the element's child count.
|
inline |
Get the element's content.
|
inline |
Get the name of the element.
XMLElement & getParent | ( | ) |
Get the parent element of this element.
const XMLElement & getParent | ( | ) | const |
Get the parent element of this element.
bool hasAttributes | ( | ) | const |
Test if the element has any attributes.
bool hasChild | ( | const String & | name | ) | const |
Test if the element has at least one child element with the given name.
name | The name. |
InvalidArgumentException | If the name is invalid. |
bool hasChildren | ( | ) | const |
Test if the element has children.
|
inline |
Test if the element has content.
|
inline |
Test if the element is a "null" element.
|
inline |
Boolean evaluation cast operator.
|
inline |
Test if the element is a "null" element.
XMLElement & operator= | ( | bool | val | ) |
Set the element's content to the string representation of a bool.
XMLElement & operator= | ( | long | val | ) |
Set the element's content to the string representation of a long.
XMLElement & operator= | ( | unsigned long | val | ) |
Set the element's content to the string representation of an unsigned long.
XMLElement & operator= | ( | const int64_t & | val | ) |
Set the element's content to the string representation of an int64_t.
XMLElement & operator= | ( | const uint64_t & | val | ) |
Set the element's content to the string representation of a uint64_t.
XMLElement & operator= | ( | float | val | ) |
Set the element's content to the string representation of a float.
XMLElement & operator= | ( | const double & | val | ) |
Set the element's content to the string representation of a double.
XMLElement & operator= | ( | const String & | val | ) |
Set the element's content.
Equivalent to setContent().
XMLElement & operator[] | ( | const String & | name | ) |
Get the first child with the given name.
If no such child exists, a new child with the given name is automatically added.
name | The name. |
InvalidArgumentException | If the name is invalid. |
XMLElement & operator[] | ( | const char * | name | ) |
Get the first child with the given name.
If no such child exists, a new child with the given name is automatically added.
name | The name. |
InvalidArgumentException | If the name is invalid. |
|
inline |
Get the first child with the given name.
name | The name. |
InvalidArgumentException | If the name is invalid. |
|
inline |
Get the first child with the given name.
name | The name. |
InvalidArgumentException | If the name is invalid. |
XMLElement & operator[] | ( | int | index | ) |
Get the child at the given index.
index | The index. |
const XMLElement & operator[] | ( | int | index | ) | const |
Get the child at the given index.
index | The index. |
void removeAttributes | ( | ) |
Remove all attributes from the element.
void removeChildren | ( | ) |
Remove (and delete) all of the child elements.
void removeChildren | ( | const String & | name | ) |
Remove (and delete) all of the child elements with the given name.
name | The name. |
InvalidArgumentException | If the name is invalid. |
Set a String attribute in the element.
name | The attribute name. |
value | The attribute value. If the element already contains an attribute with the given name, the old value is overwritten. |
InvalidArgumentException | If the name is invalid. |
void setAttribute | ( | const String & | name, |
int | value | ||
) |
Set an integer attribute in the element.
name | The attribute name. |
value | The attribute value. If the element already contains an attribute with the given name, the old value is overwritten. |
InvalidArgumentException | If the name is invalid. |
void setAttribute | ( | const String & | name, |
const int64_t & | value | ||
) |
Set a 64-bit integer attribute in the element.
name | The attribute name. |
value | The attribute value. If the element already contains an attribute with the given name, the old value is overwritten. |
InvalidArgumentException | If the name is invalid. |
void setAttribute | ( | const String & | name, |
const double & | value | ||
) |
Set a floating point attribute in the element.
name | The attribute name. |
value | The attribute value. If the element already contains an attribute with the given name, the old value is overwritten. |
InvalidArgumentException | If the name is invalid. |
void setAttribute | ( | const String & | name, |
bool | value | ||
) |
Set a boolean attribute in the element.
name | The attribute name. |
value | The attribute value. If the element already contains an attribute with the given name, the old value is overwritten. |
InvalidArgumentException | If the name is invalid. |
|
inline |
Set the element's content.
content | The content. |
bool toBool | ( | ) | const |
Return the element's content as a bool.
double toDouble | ( | ) | const |
Return the element's content as a double.
float toFloat | ( | ) | const |
Return the element's content as a float.
int toInt | ( | ) | const |
Return the element's content as a long.
int64_t toInt64 | ( | ) | const |
Return the element's content as an int64_t.
|
inline |
Return the element's content as a String.
Equivalent to getContent().
uint_t toUInt | ( | ) | const |
Return the element's content as an unsigned long.
uint64_t toUInt64 | ( | ) | const |
Return the element's content as a uint64_t.
|
static |
Determine if an element or attribute name is valid.
void write | ( | std::ostream & | stream, |
int | depth, | ||
uint_t | tabWidth | ||
) | const |
Write the element (and its children, recursively) to a stream.
|
friend |
|
friend |
|
friend |
|
static |
The "null" element.