XMLElement Class Reference

An XML element. More...

#include <xmlparser.h>

Inheritance diagram for XMLElement:

GenObject

List of all members.

Public Types

enum  Type {
  StreamStart, StreamEnd, StreamError, StreamFeatures,
  Register, Starttls, Handshake, Auth,
  Challenge, Abort, Aborted, Response,
  Proceed, Success, Failure, Mechanisms,
  Mechanism, Session, Iq, Message,
  Presence, Error, Query, Jingle,
  Description, PayloadType, Transport, Candidate,
  Body, Feature, Bind, Resource,
  Jid, Username, Password, Digest,
  Required, Dtmf, DtmfMethod, Command,
  Text, Item, Group, Unknown,
  Invalid
}

Public Member Functions

 XMLElement ()
 XMLElement (const XMLElement &src)
 XMLElement (const XMLElement &src, bool response, bool result)
 XMLElement (const char *name, NamedList *attributes=0, const char *text=0)
 XMLElement (Type type, NamedList *attributes=0, const char *text=0)
 XMLElement (NamedList &src, const char *prefix)
virtual ~XMLElement ()
Type type () const
const char * name () const
bool nameIs (const char *text) const
bool valid () const
void changeType (Type t)
void toString (String &dest, bool unclose=false) const
void toList (NamedList &dest, const char *prefix)
void setAttribute (const char *name, const char *value)
void setAttributeValid (const char *name, const String &value)
void setAttribute (const char *name, int value)
const char * getAttribute (const char *name) const
bool getAttribute (const char *name, String &value) const
bool hasAttribute (const char *name, const char *value) const
const char * getText () const
void addChild (XMLElement *element)
XMLElementfindFirstChild (const char *name=0)
XMLElementfindFirstChild (Type type)
bool hasChild (const char *name)
bool hasChild (Type type)
XMLElementfindNextChild (XMLElement *element, const char *name=0)
XMLElementfindNextChild (XMLElement *element, Type type)
const TiXmlAttributefirstAttribute () const
virtual void * getObject (const String &name) const
virtual const StringtoString () const
virtual void destruct ()

Static Public Member Functions

static const char * typeName (Type type)
static bool isType (const char *txt, Type type)
static XMLElementgetXml (NamedList &list, bool stole=false, const char *name="xml", const char *value=0)

Protected Member Functions

 XMLElement (TiXmlElement *element, bool owner)
TiXmlElementget () const
TiXmlElementreleaseOwnership ()

Static Protected Attributes

static TokenDict s_names []

Friends

class XMLParser


Detailed Description

An XML element.

This class holds an XML element


Member Enumeration Documentation

enum Type

Element type as enumeration


Constructor & Destructor Documentation

XMLElement (  ) 

Constructor. Constructs a StreamEnd element

XMLElement ( const XMLElement src  ) 

Copy constructor

Parameters:
src Source element

XMLElement ( const XMLElement src,
bool  response,
bool  result 
)

Constructor. Partially build this element from another one. Copy name and 'to', 'from', 'type', 'id' attributes

Parameters:
src Source element
response True to reverse 'to' and 'from' attributes
result True to set type to "result", false to set it to "error". Ignored if response is false

XMLElement ( const char *  name,
NamedList attributes = 0,
const char *  text = 0 
)

Constructor. Constructs an XML element with a TiXmlElement element with the given name. Used for outgoing elements

Parameters:
name The element's name
attributes Optional list of attributes
text Optional text for the XML element

XMLElement ( Type  type,
NamedList attributes = 0,
const char *  text = 0 
)

Constructor. Constructs an XML element with a TiXmlElement element with the given type's name. Used for outgoing elements

Parameters:
type The element's type
attributes Optional list of attributes
text Optional text for the XML element

XMLElement ( NamedList src,
const char *  prefix 
)

Constructor. Build this XML element from a list containing name, attributes and text. Element's name must be a parameter whose name must be equal to prefix. Element's text must be a parameter whose name is prefix followed by a dot. The list of attributes will be built from parameters starting with prefix.attributename

Parameters:
src The list containing data used to build this XML element
prefix The prefix used to search the list of parameters

virtual ~XMLElement (  )  [virtual]

Destructor. Deletes the underlying TiXmlElement if owned

XMLElement ( TiXmlElement element,
bool  owner 
) [protected]

Constructor. Constructs an XML element from a TiXmlElement. Used to extract elements from parser and access the children. When extracting elements from parser the object will own the TiXmlElement. When accessing the children, the object will not own the TiXmlElement

Parameters:
element Pointer to a valid TiXmlElement
owner Owner flag


Member Function Documentation

Type type (  )  const [inline]

Get the type of this object

Returns:
The type of this object as enumeration

const char* name (  )  const [inline]

Get the TiXmlElement's name

Returns:
The name of the TiXmlElement object or 0

bool nameIs ( const char *  text  )  const [inline]

Check if the TiXmlElement's name is the given text

Parameters:
text Text to compare with
Returns:
False if text is 0 or not equal to name

bool valid (  )  const [inline]

Get the validity of this object

Returns:
True if m_element is non null

void changeType ( Type  t  )  [inline]

Change the type of this object

Parameters:
t The new type of this object

void toString ( String dest,
bool  unclose = false 
) const

Put the element in a buffer

Parameters:
dest Destination string
unclose True to leave the tag unclosed

Referenced by XMLElementOut::toBuffer().

void toList ( NamedList dest,
const char *  prefix 
)

Put this element's name, text and attributes to a list of parameters

Parameters:
dest Destination list
prefix Prefix to add to parameters

void setAttribute ( const char *  name,
const char *  value 
)

Set the value of an existing attribute or adds a new one

Parameters:
name Attribute's name
value Attribute's value

void setAttributeValid ( const char *  name,
const String value 
) [inline]

Set the value of an existing attribute or adds a new one if the value's length is not 0

Parameters:
name Attribute's name
value Attribute's value

void setAttribute ( const char *  name,
int  value 
) [inline]

Set the value of an existing attribute or adds a new one from an integer

Parameters:
name Attribute's name
value Attribute's value

const char* getAttribute ( const char *  name  )  const

Get the value of an attribute

Parameters:
name Attribute's name
Returns:
Attribute's value. May be 0 if doesn't exists or empty

bool getAttribute ( const char *  name,
String value 
) const [inline]

Get the value of an attribute

Parameters:
name Attribute's name
value Destination string
Returns:
True if attribute with the given name exists and is not empty

References String::length().

bool hasAttribute ( const char *  name,
const char *  value 
) const

Check if an attribute with the given name and value exists

Parameters:
name Attribute's name
value Attribute's value
Returns:
True/False

const char* getText (  )  const

Get the text of this XML element

Returns:
Pointer to the text of this XML element or 0

void addChild ( XMLElement element  ) 

Add a child to this object. Release the received element

Parameters:
element XMLElement to add

Referenced by JGTransport::addTo().

XMLElement* findFirstChild ( const char *  name = 0  ) 

Find the first child element of this one. If an element is returned, it is a newly allocated one, not owning its TiXmlElement pointer

Parameters:
name Optional name of the child
Returns:
Pointer to an XMLElement or 0 if not found

XMLElement* findFirstChild ( Type  type  )  [inline]

Find the first child element of the given type. If an element is returned, it is a newly allocated one, not owning its TiXmlElement pointer

Parameters:
type Child's type to find
Returns:
Pointer to an XMLElement or 0 if not found

bool hasChild ( const char *  name  )  [inline]

Check if this element has a given child

Parameters:
name Optional name of the child (check for the first one if 0)
Returns:
True if this element has the desired child

References TelEngine::destruct().

bool hasChild ( Type  type  )  [inline]

Check if this element has a given child

Parameters:
type Child's type to find
Returns:
True if this element has the desired child

XMLElement* findNextChild ( XMLElement element,
const char *  name = 0 
)

Find the next child element. Delete the starting element if not 0. If an element is returned, it is a newly allocated one, not owning its TiXmlElement pointer

Parameters:
element Starting XMLElement. O to find from the beginning
name Optional name of the child
Returns:
Pointer to an XMLElement or 0 if not found

XMLElement* findNextChild ( XMLElement element,
Type  type 
) [inline]

Find the next child element of the given type. Delete the starting element if not 0. If an element is returned, it is a newly allocated one, not owning its TiXmlElement pointer

Parameters:
element Starting XMLElement. O to find from the beginning
type Child's type to find
Returns:
Pointer to an XMLElement or 0 if not found

const TiXmlAttribute* firstAttribute (  )  const [inline]

Find the first attribute

Returns:
Pointer to the first attribute or 0

static const char* typeName ( Type  type  )  [inline, static]

Get the name associated with the given type

Parameters:
type Element type as enumeration
Returns:
Pointer to the name or 0

References TelEngine::lookup().

static bool isType ( const char *  txt,
Type  type 
) [inline, static]

Check if the given text is equal to the one associated with the given type

Parameters:
txt Text to compare
type Element type as enumeration
Returns:
True if txt equals the text associated with the given type

virtual void* getObject ( const String name  )  const [inline, virtual]

Get a pointer to this object

Reimplemented from GenObject.

References GenObject::getObject().

virtual const String& toString (  )  const [inline, virtual]

Release memory

Reimplemented from GenObject.

virtual void destruct (  )  [inline, virtual]

Release memory

Reimplemented from GenObject.

References GenObject::destruct().

static XMLElement* getXml ( NamedList list,
bool  stole = false,
const char *  name = "xml",
const char *  value = 0 
) [static]

Get an xml element from a list's parameter

Parameters:
list The list to be searched for the given parameter
stole True to release parameter ownership (defaults to false)
name Parameter name (defaults to 'xml')
value Optional parameter value to check
Returns:
XMLElement pointer or 0. If a valid pointer is returned and stole is true the caller will own the pointer

TiXmlElement* get (  )  const [inline, protected]

Get the underlying TiXmlElement

Returns:
The underlying TiXmlElement object or 0

TiXmlElement* releaseOwnership (  )  [protected]

Release the ownership of the underlying TiXmlElement and returns it if the object owns it

Returns:
The underlying TiXmlElement object or 0 if not owned or 0


Member Data Documentation

TokenDict s_names[] [static, protected]

Associations between XML element name and type


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

Generated on Mon Aug 11 16:18:52 2008 for Yate by  doxygen 1.5.6