1
#ifndef CPPUNIT_TOOLS_XMLELEMENT_H
2
#define CPPUNIT_TOOLS_XMLELEMENT_H
4
#include <cppunit/Portability.h>
6
#if CPPUNIT_NEED_DLL_DECL
7
#pragma warning( push )
8
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
11
#include <cppunit/portability/CppUnitDeque.h>
20
#if CPPUNIT_NEED_DLL_DECL
21
// template class CPPUNIT_API std::deque<XmlElement *>;
25
/*! \brief A XML Element.
28
* - a name, specified on construction,
29
* - a content, specified on construction (may be empty),
30
* - zero or more attributes, added with addAttribute(),
31
* - zero or more child elements, added with addElement().
33
class CPPUNIT_API XmlElement
36
/*! \brief Constructs an element with the specified name and string content.
37
* \param elementName Name of the element. Must not be empty.
38
* \param content Content of the element.
40
XmlElement( std::string elementName,
41
std::string content ="" );
43
/*! \brief Constructs an element with the specified name and numeric content.
44
* \param elementName Name of the element. Must not be empty.
45
* \param numericContent Content of the element.
47
XmlElement( std::string elementName,
50
/*! \brief Destructs the element and its child elements.
52
virtual ~XmlElement();
54
/*! \brief Returns the name of the element.
55
* \return Name of the element.
57
std::string name() const;
59
/*! \brief Returns the content of the element.
60
* \return Content of the element.
62
std::string content() const;
64
/*! \brief Sets the name of the element.
65
* \param name New name for the element.
67
void setName( const std::string &name );
69
/*! \brief Sets the content of the element.
70
* \param content New content for the element.
72
void setContent( const std::string &content );
74
/*! \overload void setContent( const std::string &content )
76
void setContent( int numericContent );
78
/*! \brief Adds an attribute with the specified string value.
79
* \param attributeName Name of the attribute. Must not be an empty.
80
* \param value Value of the attribute.
82
void addAttribute( std::string attributeName,
85
/*! \brief Adds an attribute with the specified numeric value.
86
* \param attributeName Name of the attribute. Must not be empty.
87
* \param numericValue Numeric value of the attribute.
89
void addAttribute( std::string attributeName,
92
/*! \brief Adds a child element to the element.
93
* \param element Child element to add. Must not be \c NULL.
95
void addElement( XmlElement *element );
97
/*! \brief Returns the number of child elements.
98
* \return Number of child elements (element added with addElement()).
100
int elementCount() const;
102
/*! \brief Returns the child element at the specified index.
103
* \param index Zero based index of the element to return.
104
* \returns Element at the specified index. Never \c NULL.
105
* \exception std::invalid_argument if \a index < 0 or index >= elementCount().
107
XmlElement *elementAt( int index ) const;
109
/*! \brief Returns the first child element with the specified name.
110
* \param name Name of the child element to return.
111
* \return First child element found which is named \a name.
112
* \exception std::invalid_argument if there is no child element with the specified
115
XmlElement *elementFor( const std::string &name ) const;
117
/*! \brief Returns a XML string that represents the element.
118
* \param indent String of spaces representing the amount of 'indent'.
119
* \return XML string that represents the element, its attributes and its
122
std::string toString( const std::string &indent = "" ) const;
125
typedef std::pair<std::string,std::string> Attribute;
127
std::string attributesAsString() const;
128
std::string escape( std::string value ) const;
132
std::string m_content;
134
typedef CppUnitDeque<Attribute> Attributes;
135
Attributes m_attributes;
137
typedef CppUnitDeque<XmlElement *> Elements;
144
#if CPPUNIT_NEED_DLL_DECL
145
#pragma warning( pop )
149
#endif // CPPUNIT_TOOLS_XMLELEMENT_H