xmlm::BasicElement< T > Class Template Reference

An XML element. More...

#include <xmlminus.h>

List of all members.

Public Types

enum  ElementType
 The type of an XML element, NORMAL, COMMENT, DECLARATION or TERMINATOR.
typedef T string_type
 The string type.
typedef string_type::value_type char_type
 The character type of the string type.
typedef string_type::traits_type traits_type
 The char traits type of the string type.
typedef string_type::allocator_type allocator_type
 The allocator type of the string type.
typedef std::basic_istream<
char_type, traits_type
istream_type
 An input stream type to use with this type of element.
typedef std::basic_ostream<
char_type, traits_type
ostream_type
 An input output type to use with this type of element.
typedef std::vector< BasicElement<
T > > 
ChildVector
 A vector of elements.
typedef std::map< string_type,
string_type
AttributeMap
 A map of attributes.

Public Member Functions

 BasicElement (istream_type &in)
 Create and parse a new XML element.
 BasicElement (istream_type &in, const std::locale &loc)
 Create and parse a new XML element.
 BasicElement (const string_type &value="", ElementType type=NORMAL)
 Create a new empty element.
 BasicElement (const string_type &value, const std::locale &loc, ElementType type=NORMAL)
 Create a new empty element.
 BasicElement (const std::locale &loc, ElementType type=NORMAL)
 Create a new empty element.
std::locale & getLocale ()
 Get this element's locale.
const std::locale & getLocale () const
 Get this element's locale.
void setLocale (const std::locale &loc)
 Set this element's locale.
const string_typegetValue () const
 Get this element's value.
string_typegetValue ()
 Get this element's value.
void setValue (const string_type &val)
 Set this element's value.
const ChildVectorgetChildren () const
 Get this element's child elements.
ChildVectorgetChildren ()
 Get this element's child elements.
const AttributeMapgetAttributes () const
 Get this element's attributes.
AttributeMapgetAttributes ()
 Get this element's attributes.
const string_typegetText () const
 Get this element's text.
string_typegetText ()
 Get this element's text.
void setText (const string_type &str)
 Set this element's text.
ElementType getType () const
 Get this element's type.
void setType (ElementType t)
 Set this element's type.
template<typename valueT>
void setAttribute (const string_type &key, const valueT &val)
 Set this element's attribute.
template<typename valueT>
valueT getAttribute (const string_type &key) const
 Get this element's attribute.
const string_typegetAttributeRaw (const string_type &key) const
 Get this element's attribute.
string_typegetAttributeRaw (const string_type &key)
 Get this element's attribute.
void setAttributeRaw (const string_type &key, const string_type &val)
 Set this element's attribute.
bool hasAttribute (const string_type &key) const
 Check if this element has an attribute.
void print (ostream_type &out, int indent=0) const
 Write this element to an output stream.
void parse (istream_type &in)
 Read and parse this element from a stream.
const BasicElement< T > & getChild (const string_type &val) const
 Get a child element of this element.
BasicElement< T > & getChild (const string_type &val)
 Get a child element of this element.

Static Public Member Functions

static void entityEncode (string_type &str)
 Encode all XML entities in a string.
static void entityDecode (string_type &str)
 Decode all XML entities in a string.


Detailed Description

template<class T>
class xmlm::BasicElement< T >

An XML element.

Parameters:
T the string type for this element


Constructor & Destructor Documentation

template<class T>
xmlm::BasicElement< T >::BasicElement ( istream_type in  )  [inline]

Create and parse a new XML element.

This element's locale will be queried from the input stream.

Parameters:
in the input stream where to read the XML data
Exceptions:
ParseError on parsing/syntax errors
std::runtime_error on I/O errors

template<class T>
xmlm::BasicElement< T >::BasicElement ( istream_type in,
const std::locale &  loc 
) [inline]

Create and parse a new XML element.

The locale will be imbue'd to the input stream and the previous locale will be restored after the parsing.

Parameters:
in the input stream where to read the XML
loc the locale to use
Exceptions:
ParseError on parsing/syntax errors
std::runtime_error on I/O errors

template<class T>
xmlm::BasicElement< T >::BasicElement ( const string_type value = "",
ElementType  type = NORMAL 
) [inline]

Create a new empty element.

Parameters:
value the value of this XML element
type the Type of this XML element

template<class T>
xmlm::BasicElement< T >::BasicElement ( const string_type value,
const std::locale &  loc,
ElementType  type = NORMAL 
) [inline]

Create a new empty element.

Parameters:
value the value of this XML element
loc the locale to use with this element8
type the Type of this XML element

template<class T>
xmlm::BasicElement< T >::BasicElement ( const std::locale &  loc,
ElementType  type = NORMAL 
) [inline]

Create a new empty element.

Parameters:
loc the locale to use with this element
type the Type of this XML element


Member Function Documentation

template<class T>
std::locale& xmlm::BasicElement< T >::getLocale (  )  [inline]

Get this element's locale.

Returns:
this element's locale

template<class T>
const std::locale& xmlm::BasicElement< T >::getLocale (  )  const [inline]

Get this element's locale.

Returns:
this element's locale

template<class T>
void xmlm::BasicElement< T >::setLocale ( const std::locale &  loc  )  [inline]

Set this element's locale.

Parameters:
loc the new locale of this element

template<class T>
const string_type& xmlm::BasicElement< T >::getValue (  )  const [inline]

Get this element's value.

Returns:
this element's value

template<class T>
string_type& xmlm::BasicElement< T >::getValue (  )  [inline]

Get this element's value.

Returns:
this element's value

template<class T>
void xmlm::BasicElement< T >::setValue ( const string_type val  )  [inline]

Set this element's value.

Parameters:
val this element's new value

template<class T>
const ChildVector& xmlm::BasicElement< T >::getChildren (  )  const [inline]

Get this element's child elements.

Returns:
a vector that has this element's all child elements

template<class T>
ChildVector& xmlm::BasicElement< T >::getChildren (  )  [inline]

Get this element's child elements.

Returns:
a vector that has this element's all child elements

template<class T>
const AttributeMap& xmlm::BasicElement< T >::getAttributes (  )  const [inline]

Get this element's attributes.

Returns:
a map with this element's attributes

template<class T>
AttributeMap& xmlm::BasicElement< T >::getAttributes (  )  [inline]

Get this element's attributes.

Returns:
a map with this element's attributes

template<class T>
const string_type& xmlm::BasicElement< T >::getText (  )  const [inline]

Get this element's text.

Returns:
this element's text

template<class T>
string_type& xmlm::BasicElement< T >::getText (  )  [inline]

Get this element's text.

Returns:
this element's text

template<class T>
void xmlm::BasicElement< T >::setText ( const string_type str  )  [inline]

Set this element's text.

Parameters:
str this element's new text

template<class T>
ElementType xmlm::BasicElement< T >::getType (  )  const [inline]

Get this element's type.

Returns:
this element's type
See also:
ElementType

template<class T>
void xmlm::BasicElement< T >::setType ( ElementType  t  )  [inline]

Set this element's type.

Parameters:
t this element's new type
See also:
ElementType

template<class T>
template<typename valueT>
void xmlm::BasicElement< T >::setAttribute ( const string_type key,
const valueT &  val 
)

Set this element's attribute.

Set the value of an attributed named key. If such attribute does not exist, it will be created. The attribute is converted from type valueT to string_type using boost::lexical_cast.

Parameters:
key the name of the attribute
val the value of the attribute
See also:
boost::lexical_cast()

template<class T>
template<typename valueT>
valueT xmlm::BasicElement< T >::getAttribute ( const string_type key  )  const

Get this element's attribute.

Get the value of an attribute named key. If such attribute does not exist, an exception will be thrown. The attribute is converted from type string_type to valueT using boost::lexical_cast.

Parameters:
key the name of the attribute
Returns:
the value of the attribute
Exceptions:
ParseError if the attribute is not found
See also:
boost::lexical_cast()

template<class T>
const string_type& xmlm::BasicElement< T >::getAttributeRaw ( const string_type key  )  const [inline]

Get this element's attribute.

Get the value of an attribute named key. If such attribute does not exist, an exception will be thrown.

Parameters:
key the name of the attribute
Returns:
the value of the attribute
Exceptions:
ParseError if the attribute is not found

template<class T>
string_type& xmlm::BasicElement< T >::getAttributeRaw ( const string_type key  )  [inline]

Get this element's attribute.

Get the value of an attribute named key. If such attribute does not exist, an exception will be thrown.

Parameters:
key the name of the attribute
Returns:
the value of the attribute
Exceptions:
ParseError if the attribute is not found

template<class T>
void xmlm::BasicElement< T >::setAttributeRaw ( const string_type key,
const string_type val 
) [inline]

Set this element's attribute.

Set the value of attribute named key to val. If such attribute does not exist, it will be created.

Parameters:
key the name of the attribute
val the value to set to the attribute

template<class T>
bool xmlm::BasicElement< T >::hasAttribute ( const string_type key  )  const [inline]

Check if this element has an attribute.

Parameters:
key the name of the attribute
Returns:
true if the attribute exists

template<class T>
void xmlm::BasicElement< T >::print ( ostream_type out,
int  indent = 0 
) const

Write this element to an output stream.

Writes out this element and all it's subelements recursively.

Parameters:
out the output stream where to write this element
indent the level of indentation (in tab characters) for this element

template<class T>
void xmlm::BasicElement< T >::parse ( istream_type in  ) 

Read and parse this element from a stream.

Parameters:
in the input stream where to parse this element from
Exceptions:
ParseError on parsing errors
std::runtime_error on I/O errors

template<class T>
const BasicElement<T>& xmlm::BasicElement< T >::getChild ( const string_type val  )  const [inline]

Get a child element of this element.

Returns a child element with value val. If no element is found, an exception is thrown. If there are more than one elements with value val the first one will be returned.

Parameters:
val the value of the child element to find
Returns:
a reference to this element's first child element with value val
Exceptions:
ParseError if no element will be found

template<class T>
BasicElement<T>& xmlm::BasicElement< T >::getChild ( const string_type val  )  [inline]

Get a child element of this element.

Returns a child element with value val. If no element is found, an exception is thrown. If there are more than one elements with value val the first one will be returned.

Parameters:
val the value of the child element to find
Returns:
a reference to this element's first child element with value val
Exceptions:
ParseError if no element will be found

template<class T>
void xmlm::BasicElement< T >::entityEncode ( string_type str  )  [static]

Encode all XML entities in a string.

Parameters:
str the string to encode

template<class T>
void xmlm::BasicElement< T >::entityDecode ( string_type str  )  [static]

Decode all XML entities in a string.

Parameters:
str the string to decode


The documentation for this class was generated from the following file:
Generated on Fri Dec 15 19:24:38 2006 for XMLminus by  doxygen 1.5.0