Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

judo::Element Class Reference

XML Element representation class. More...

#include <judo.hpp>

Inheritance diagram for judo::Element:

judo::Node List of all members.

Public Member Functions

 Element (const std::string &name, const char **attribs=NULL)
 Default constructor.

Element * addElement (const std::string &name, const char **attribs=NULL)
 Add a new child element to "this" element.

Element * addElement (const std::string &name, const std::string &cdata, bool escaped=false)
 Add a new child element with a solitary section of character data.

CDATAaddCDATA (const char *data, int datasz, bool escaped=false)
 Add character data to "this" element.

void putAttrib (const std::string &name, const std::string &value)
 Store an attribute (key/value pair) on this element.

std::string getAttrib (const std::string &name) const
 Retrieve an attribute value.

void delAttrib (const std::string &name)
 Delete an attribute key/value.

bool cmpAttrib (const std::string &name, const std::string &value) const
 Compare an attribute value to a string.

std::string toString () const
 Get a properly escaped XML string representation of this object.

std::string toStringEx (bool recursive=false, bool closetag=false) const
 Custom version of Element::toString.

void accumulate (XMLAccumulator &acc) const
 Accumulate a properly escaped XML string representation of this object.

std::string getCDATA () const
 Retrieve the first CDATA child of this element.

void appendChild (Node *child)
 Append child node to this Element.

NodedetachChild (iterator it)
 Detach a child node from this element.

bool empty () const
 Determine if this Element is empty (i.e.

int size () const
 Determine the number of child nodes this Element has.

iterator begin ()
 Return an iterator to the first child Node.

const_iterator begin () const
 Return a const iterator to the first child Node.

iterator end ()
 Return a iterator indicating the end of child nodes.

const_iterator end () const
 Return a const iterator indicating the end of child nodes.

iterator find (const std::string &name, Node::Type type=Node::ntElement)
 Locate the first child node which has the specified name and type.

const_iterator find (const std::string &name, Node::Type type=Node::ntElement) const
 Locate the first child node which has the specified name and type.

void Element::erase (Element::iterator it)
 Delete the child Node designated by the supplied iterator.

Element * findElement (const std::string &name)
 Locate the first child node which has the specified name and is an Element.

const Element * findElement (const std::string &name) const
 Locate the first child node which has the specified name and is an Element.

void eraseElement (const std::string &name)
 Locate the first child Element which has the specified name and erase it.

std::string getChildCData (const std::string &name) const
 Locate the first child node which has the specified name and extract the CDATA from it.

int getChildCDataAsInt (const std::string &name, int defaultvalue) const
 Locate the first child node which has the specified name and extract the CDATA from it, converting the value into an integer.


Detailed Description

XML Element representation class.

Definition at line 235 of file judo.hpp.


Constructor & Destructor Documentation

Element::Element const std::string &    name,
const char **    attribs = NULL
 

Default constructor.

Parameters:
name Name of this tag
attribs Expat-style attributes of this element

Definition at line 57 of file Element.cpp.

Referenced by addElement().


Member Function Documentation

void Element::accumulate XMLAccumulator &    acc const [virtual]
 

Accumulate a properly escaped XML string representation of this object.

See also:
Node::accumulate

Implements judo::Node.

Definition at line 276 of file Element.cpp.

References judo::Node::getName().

Referenced by toString().

CDATA * Element::addCDATA const char *    data,
int    datasz,
bool    escaped = false
 

Add character data to "this" element.

This automatically merges adjacent sections of CDATA (if the parser splits them up).

Parameters:
data Character data to add
datasz Length of the character data
escaped Is the text escaped?
Returns:
Pointer to the object which holds the data

Definition at line 154 of file Element.cpp.

References judo::CDATA::appendText().

Referenced by addElement().

Element * Element::addElement const std::string &    name,
const std::string &    cdata,
bool    escaped = false
 

Add a new child element with a solitary section of character data.

Parameters:
name Name of child element
value Character data which will be stored in new child element
escaped Is the text escaped?
Returns:
Pointer to the new child element

Definition at line 137 of file Element.cpp.

References addCDATA(), and addElement().

Element * Element::addElement const std::string &    name,
const char **    attribs = NULL
 

Add a new child element to "this" element.

Parameters:
name Name of child element
attribs Expat-style attributes of the new child element
Returns:
Pointer to the new child element

Definition at line 122 of file Element.cpp.

References Element().

Referenced by addElement(), jabberoo::Packet::addX(), jabberoo::DiscoDB::cache(), jabberoo::Roster::deleteUser(), jabberoo::Roster::fetch(), jabberoo::Message::Message(), jabberoo::Session::queryNamespace(), jabberoo::Message::setBody(), jabberoo::Presence::setPriority(), jabberoo::Presence::setShow(), jabberoo::Presence::setStatus(), jabberoo::Message::setSubject(), jabberoo::Message::setThread(), and jabberoo::Roster::update().

void judo::Element::appendChild Node   child [inline]
 

Append child node to this Element.

Parameters:
child child node pointer

Definition at line 271 of file judo.hpp.

const_iterator judo::Element::begin   const [inline]
 

Return a const iterator to the first child Node.

Definition at line 300 of file judo.hpp.

iterator judo::Element::begin   [inline]
 

Return an iterator to the first child Node.

Definition at line 294 of file judo.hpp.

Referenced by jabberoo::Packet::eraseX(), find(), jabberoo::Packet::findX(), and jabberoo::Roster::update().

bool Element::cmpAttrib const std::string &    name,
const std::string &    value
const
 

Compare an attribute value to a string.

Parameters:
name Attribute name/key to compare against
value Value to compare against the attribute value
Returns:
True if the user-provided value is the same as the value of the attribute

Definition at line 211 of file Element.cpp.

Referenced by jabberoo::Roster::update().

void Element::delAttrib const std::string &    name
 

Delete an attribute key/value.

Parameters:
name Attribute name/key to delete

Definition at line 199 of file Element.cpp.

Node * Element::detachChild iterator    it
 

Detach a child node from this element.

The iterator is invalidated after this call.

Parameters:
it iterator pointing to child node pointer
Returns:
- node pointer of child node

Definition at line 398 of file Element.cpp.

void judo::Element::Element::erase Element::iterator    it [inline]
 

Delete the child Node designated by the supplied iterator.

Parameters:
it Iterator pointing to the child Node

Definition at line 322 of file judo.hpp.

References Element::erase().

Referenced by Element::erase().

bool judo::Element::empty   const [inline]
 

Determine if this Element is empty (i.e.

has no child nodes)

Returns:
True if no child nodes exist

Definition at line 280 of file judo.hpp.

const_iterator judo::Element::end   const [inline]
 

Return a const iterator indicating the end of child nodes.

Definition at line 312 of file judo.hpp.

iterator judo::Element::end   [inline]
 

Return a iterator indicating the end of child nodes.

Definition at line 306 of file judo.hpp.

Referenced by eraseElement(), jabberoo::Packet::eraseX(), find(), findElement(), jabberoo::Packet::findX(), and jabberoo::Roster::update().

void Element::eraseElement const std::string &    name
 

Locate the first child Element which has the specified name and erase it.

As a result of this, the child Element's sub-children are also removed.

Definition at line 385 of file Element.cpp.

References end(), and find().

Element::const_iterator Element::find const std::string &    name,
Node::Type    type = Node::ntElement
const
 

Locate the first child node which has the specified name and type.

Parameters:
name Name of the child Node to find.
Returns:
const Iterator pointing to the child Node, or end() if no such child was found

Definition at line 334 of file Element.cpp.

References begin(), and end().

Element::iterator Element::find const std::string &    name,
Node::Type    type = Node::ntElement
 

Locate the first child node which has the specified name and type.

Parameters:
name Name of the child Node to find.
Returns:
Iterator pointing to the child Node, or end() if no such child was found

Definition at line 316 of file Element.cpp.

References begin(), and end().

Referenced by eraseElement(), and findElement().

const Element * Element::findElement const std::string &    name const
 

Locate the first child node which has the specified name and is an Element.

Parameters:
name Name of the child Element to find.
Returns:
Pointer to the matching child Element, or NULL if no such child was found

Definition at line 370 of file Element.cpp.

References end(), and find().

Element * Element::findElement const std::string &    name
 

Locate the first child node which has the specified name and is an Element.

Parameters:
name Name of the child Element to find.
Returns:
Pointer to the matching child Element, or NULL if no such child was found

Definition at line 354 of file Element.cpp.

References end(), and find().

Referenced by getChildCData(), getChildCDataAsInt(), jabberoo::Packet::getErrorCode(), jabberoo::Message::setBody(), jabberoo::Message::setSubject(), and jabberoo::Message::setThread().

string Element::getAttrib const std::string &    name const
 

Retrieve an attribute value.

Parameters:
name Attribute name/key to retrieve
Returns:
Value of the attribute

Definition at line 186 of file Element.cpp.

Referenced by jabberoo::Packet::getFrom(), jabberoo::Packet::getID(), jabberoo::Packet::getTo(), jabberoo::Session::onDocumentStart(), and jabberoo::Roster::update().

string Element::getCDATA   const
 

Retrieve the first CDATA child of this element.

Returns:
a reference to the first CDATA string

Definition at line 296 of file Element.cpp.

Referenced by getChildCData(), and getChildCDataAsInt().

std::string Element::getChildCData const std::string &    name const
 

Locate the first child node which has the specified name and extract the CDATA from it.

Parameters:
name Name of the child Element to find.
Returns:
String with CDATA value within the child Element, or empty string ("") if no such child was found

Definition at line 412 of file Element.cpp.

References findElement(), and getCDATA().

Referenced by jabberoo::Message::getBody(), jabberoo::Packet::getError(), jabberoo::Presence::getPriority(), jabberoo::Presence::getStatus(), jabberoo::Message::getSubject(), and jabberoo::Message::getThread().

int Element::getChildCDataAsInt const std::string &    name,
int    defaultvalue
const
 

Locate the first child node which has the specified name and extract the CDATA from it, converting the value into an integer.

Parameters:
name Name of the child Element to find
default Default value of the integer (in case conversion fails)
Returns:
Integer value of the CDATA value within the child Element, or the default value if no child was found or integer conversion failed

Definition at line 429 of file Element.cpp.

References findElement(), and getCDATA().

void Element::putAttrib const std::string &    name,
const std::string &    value
 

Store an attribute (key/value pair) on this element.

Parameters:
name Attribute name/key value Attribute value

Definition at line 176 of file Element.cpp.

Referenced by jabberoo::DiscoDB::cache(), jabberoo::Roster::deleteUser(), jabberoo::Roster::fetch(), jabberoo::Session::queryNamespace(), jabberoo::Packet::setFrom(), jabberoo::Packet::setID(), jabberoo::Packet::setTo(), jabberoo::Presence::setType(), jabberoo::Message::setType(), and jabberoo::Roster::update().

int judo::Element::size   const [inline]
 

Determine the number of child nodes this Element has.

Prefer ::empty to comparing size() == 0

Returns:
Number of child nodes in this Element

Definition at line 288 of file judo.hpp.

string Element::toString   const [virtual]
 

Get a properly escaped XML string representation of this object.

See also:
Node::toString

Implements judo::Node.

Definition at line 225 of file Element.cpp.

References accumulate().

Referenced by jabberoo::DiscoDB::cache(), jabberoo::Roster::deleteUser(), jabberoo::Roster::fetch(), jabberoo::Session::queryNamespace(), jabberoo::Packet::toString(), and jabberoo::Roster::update().

string Element::toStringEx bool    recursive = false,
bool    closetag = false
const
 

Custom version of Element::toString.

Permits non-recursive serialization of the Element to a properly escaped XML string representation.

Parameters:
recursive Determines if the Element is recursively serialization. Default is false.
closetag Determines if the Element is closed after serialization. Default is false.
See also:
Node::toString

Definition at line 245 of file Element.cpp.

References judo::Node::getName().


The documentation for this class was generated from the following files:
Generated on Thu Jul 24 13:31:55 2003 for jabberoo by doxygen1.3-rc3