CppUnit project page | FAQ | CppUnit home page |
A XML Element. More...
#include <XmlElement.h>
Public Member Functions | |
XmlElement (std::string elementName, std::string content="") | |
Constructs an element with the specified name and string content. | |
XmlElement (std::string elementName, int numericContent) | |
Constructs an element with the specified name and numeric content. | |
virtual | ~XmlElement () |
Destructs the element and its child elements. | |
std::string | name () const |
Returns the name of the element. | |
std::string | content () const |
Returns the content of the element. | |
void | setName (const std::string &name) |
Sets the name of the element. | |
void | setContent (const std::string &content) |
Sets the content of the element. | |
void | setContent (int numericContent) |
void | addAttribute (std::string attributeName, std::string value) |
Adds an attribute with the specified string value. | |
void | addAttribute (std::string attributeName, int numericValue) |
Adds an attribute with the specified numeric value. | |
void | addElement (XmlElement *element) |
Adds a child element to the element. | |
int | elementCount () const |
Returns the number of child elements. | |
XmlElement * | elementAt (int index) const |
Returns the child element at the specified index. | |
XmlElement * | elementFor (const std::string &name) const |
Returns the first child element with the specified name. | |
std::string | toString (const std::string &indent="") const |
Returns a XML string that represents the element. | |
Private Types | |
typedef std::pair< std::string, std::string > | Attribute |
typedef CppUnitDeque< Attribute > | Attributes |
typedef CppUnitDeque < XmlElement * > | Elements |
Private Member Functions | |
std::string | attributesAsString () const |
std::string | escape (std::string value) const |
Private Attributes | |
std::string | m_name |
std::string | m_content |
Attributes | m_attributes |
Elements | m_elements |
A XML Element.
A XML element has:
typedef std::pair<std::string,std::string> XmlElement::Attribute [private] |
typedef CppUnitDeque<Attribute> XmlElement::Attributes [private] |
typedef CppUnitDeque<XmlElement *> XmlElement::Elements [private] |
CPPUNIT_NS_BEGIN XmlElement::XmlElement | ( | std::string | elementName, |
std::string | content = "" |
||
) |
Constructs an element with the specified name and string content.
elementName | Name of the element. Must not be empty. |
content | Content of the element. |
XmlElement::XmlElement | ( | std::string | elementName, |
int | numericContent | ||
) |
Constructs an element with the specified name and numeric content.
elementName | Name of the element. Must not be empty. |
numericContent | Content of the element. |
XmlElement::~XmlElement | ( | ) | [virtual] |
Destructs the element and its child elements.
void XmlElement::addAttribute | ( | std::string | attributeName, |
std::string | value | ||
) |
Adds an attribute with the specified string value.
attributeName | Name of the attribute. Must not be an empty. |
value | Value of the attribute. |
void XmlElement::addAttribute | ( | std::string | attributeName, |
int | numericValue | ||
) |
Adds an attribute with the specified numeric value.
attributeName | Name of the attribute. Must not be empty. |
numericValue | Numeric value of the attribute. |
void XmlElement::addElement | ( | XmlElement * | element | ) |
Adds a child element to the element.
element | Child element to add. Must not be NULL . |
std::string XmlElement::attributesAsString | ( | ) | const [private] |
std::string XmlElement::content | ( | ) | const |
Returns the content of the element.
XmlElement * XmlElement::elementAt | ( | int | index | ) | const |
Returns the child element at the specified index.
index | Zero based index of the element to return. |
NULL
. std::invalid_argument | if index < 0 or index >= elementCount(). |
int XmlElement::elementCount | ( | ) | const |
Returns the number of child elements.
XmlElement * XmlElement::elementFor | ( | const std::string & | name | ) | const |
Returns the first child element with the specified name.
name | Name of the child element to return. |
std::invalid_argument | if there is no child element with the specified name. |
std::string XmlElement::escape | ( | std::string | value | ) | const [private] |
std::string XmlElement::name | ( | ) | const |
Returns the name of the element.
void XmlElement::setContent | ( | int | numericContent | ) |
void XmlElement::setContent | ( | const std::string & | content | ) |
Sets the content of the element.
content | New content for the element. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void XmlElement::setName | ( | const std::string & | name | ) |
Sets the name of the element.
name | New name for the element. |
std::string XmlElement::toString | ( | const std::string & | indent = "" | ) | const |
Returns a XML string that represents the element.
indent | String of spaces representing the amount of 'indent'. |
Attributes XmlElement::m_attributes [private] |
std::string XmlElement::m_content [private] |
Elements XmlElement::m_elements [private] |
std::string XmlElement::m_name [private] |
|
hosts this site. |
Send comments to: CppUnit Developers |