CppUnit project page FAQ

Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
XmlElement Class Reference

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. More...
 
 XmlElement (std::string elementName, int numericContent)
 Constructs an element with the specified name and numeric content. More...
 
virtual ~XmlElement ()
 Destructs the element and its child elements. More...
 
std::string name () const
 Returns the name of the element. More...
 
std::string content () const
 Returns the content of the element. More...
 
void setName (const std::string &name)
 Sets the name of the element. More...
 
void setContent (const std::string &content)
 Sets the content of the element. More...
 
void setContent (int numericContent)
 
void addAttribute (std::string attributeName, std::string value)
 Adds an attribute with the specified string value. More...
 
void addAttribute (std::string attributeName, int numericValue)
 Adds an attribute with the specified numeric value. More...
 
void addElement (XmlElement *element)
 Adds a child element to the element. More...
 
int elementCount () const
 Returns the number of child elements. More...
 
XmlElementelementAt (int index) const
 Returns the child element at the specified index. More...
 
XmlElementelementFor (const std::string &name) const
 Returns the first child element with the specified name. More...
 
std::string toString (const std::string &indent="") const
 Returns a XML string that represents the element. More...
 

Private Types

typedef std::pair< std::string, std::string > Attribute
 
typedef std::deque< AttributeAttributes
 
typedef std::deque< 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
 

Detailed Description

A XML Element.

A XML element has:

Member Typedef Documentation

◆ Attribute

typedef std::pair<std::string,std::string> XmlElement::Attribute
private

◆ Attributes

typedef std::deque<Attribute> XmlElement::Attributes
private

◆ Elements

typedef std::deque<XmlElement *> XmlElement::Elements
private

Constructor & Destructor Documentation

◆ XmlElement() [1/2]

CPPUNIT_NS_BEGIN XmlElement::XmlElement ( std::string  elementName,
std::string  content = "" 
)

Constructs an element with the specified name and string content.

Parameters
elementNameName of the element. Must not be empty.
contentContent of the element.

◆ XmlElement() [2/2]

XmlElement::XmlElement ( std::string  elementName,
int  numericContent 
)

Constructs an element with the specified name and numeric content.

Parameters
elementNameName of the element. Must not be empty.
numericContentContent of the element.

◆ ~XmlElement()

XmlElement::~XmlElement ( )
virtual

Destructs the element and its child elements.

Member Function Documentation

◆ addAttribute() [1/2]

void XmlElement::addAttribute ( std::string  attributeName,
int  numericValue 
)

Adds an attribute with the specified numeric value.

Parameters
attributeNameName of the attribute. Must not be empty.
numericValueNumeric value of the attribute.

◆ addAttribute() [2/2]

void XmlElement::addAttribute ( std::string  attributeName,
std::string  value 
)

Adds an attribute with the specified string value.

Parameters
attributeNameName of the attribute. Must not be an empty.
valueValue of the attribute.

◆ addElement()

void XmlElement::addElement ( XmlElement element)

Adds a child element to the element.

Parameters
elementChild element to add. Must not be NULL.

◆ attributesAsString()

std::string XmlElement::attributesAsString ( ) const
private

◆ content()

std::string XmlElement::content ( ) const

Returns the content of the element.

Returns
Content of the element.

◆ elementAt()

XmlElement * XmlElement::elementAt ( int  index) const

Returns the child element at the specified index.

Parameters
indexZero based index of the element to return.
Returns
Element at the specified index. Never NULL.
Exceptions
std::invalid_argumentif index < 0 or index >= elementCount().

◆ elementCount()

int XmlElement::elementCount ( ) const

Returns the number of child elements.

Returns
Number of child elements (element added with addElement()).

◆ elementFor()

XmlElement * XmlElement::elementFor ( const std::string &  name) const

Returns the first child element with the specified name.

Parameters
nameName of the child element to return.
Returns
First child element found which is named name.
Exceptions
std::invalid_argumentif there is no child element with the specified name.

◆ escape()

std::string XmlElement::escape ( std::string  value) const
private

◆ name()

std::string XmlElement::name ( ) const

Returns the name of the element.

Returns
Name of the element.

◆ setContent() [1/2]

void XmlElement::setContent ( const std::string &  content)

Sets the content of the element.

Parameters
contentNew 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.

◆ setContent() [2/2]

void XmlElement::setContent ( int  numericContent)

◆ setName()

void XmlElement::setName ( const std::string &  name)

Sets the name of the element.

Parameters
nameNew name for the element.

◆ toString()

std::string XmlElement::toString ( const std::string &  indent = "") const

Returns a XML string that represents the element.

Parameters
indentString of spaces representing the amount of 'indent'.
Returns
XML string that represents the element, its attributes and its child elements.

Member Data Documentation

◆ m_attributes

Attributes XmlElement::m_attributes
private

◆ m_content

std::string XmlElement::m_content
private

◆ m_elements

Elements XmlElement::m_elements
private

◆ m_name

std::string XmlElement::m_name
private

The documentation for this class was generated from the following files:

Send comments to:
CppUnit Developers