Yate
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends

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, VCard,
  Jingle, Description, PayloadType, Transport,
  Candidate, Body, Subject, Feature,
  Bind, Resource, Transfer, Hold,
  Active, Ringing, Mute, Registered,
  Remove, Jid, Username, Password,
  Digest, Required, Dtmf, DtmfMethod,
  Command, Text, Item, Group,
  Reason, Content, Parameter, Crypto,
  CryptoRequired, Trying, Received, File,
  Offer, Request, StreamHost, StreamHostUsed,
  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
void getAttributes (NamedList &dest) const
bool hasAttribute (const char *name, const char *value) const
const char * getText () const
void addChild (XMLElement *element)
XMLElementremoveChild (const char *name=0)
XMLElementremoveChild (Type type)
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)

Static Public Attributes

static TokenDict s_names []

Protected Member Functions

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

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

Constructor. Constructs a StreamEnd element

XMLElement ( const XMLElement src)

Copy constructor

Parameters:
srcSource 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:
srcSource element
responseTrue to reverse 'to' and 'from' attributes
resultTrue 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:
nameThe element's name
attributesOptional list of attributes
textOptional 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:
typeThe element's type
attributesOptional list of attributes
textOptional 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:
srcThe list containing data used to build this XML element
prefixThe 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:
elementPointer to a valid TiXmlElement
ownerOwner flag

Member Function Documentation

void addChild ( XMLElement element)

Add a child to this object. Release the received element

Parameters:
elementXMLElement to add
void changeType ( Type  t) [inline]

Change the type of this object

Parameters:
tThe new type of this object
virtual void destruct ( ) [inline, virtual]

Release memory

Reimplemented from GenObject.

References TelEngine::destruct().

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:
nameOptional 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:
typeChild's type to find
Returns:
Pointer to an XMLElement or 0 if not found

References XMLElement::findFirstChild().

Referenced by XMLElement::findFirstChild().

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:
elementStarting XMLElement. O to find from the beginning
nameOptional 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:
elementStarting XMLElement. O to find from the beginning
typeChild's type to find
Returns:
Pointer to an XMLElement or 0 if not found

References XMLElement::findNextChild().

Referenced by XMLElement::findNextChild().

const TiXmlAttribute* firstAttribute ( ) const [inline]

Find the first attribute

Returns:
Pointer to the first attribute or 0
TiXmlElement* get ( ) const [inline, protected]

Get the underlying TiXmlElement

Returns:
The underlying TiXmlElement object or 0
const char* getAttribute ( const char *  name) const

Get the value of an attribute

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

Referenced by JGSession::getAction().

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

Get the value of an attribute

Parameters:
nameAttribute's name
valueDestination string
Returns:
True if attribute with the given name exists and is not empty

References String::length().

void getAttributes ( NamedList dest) const

Fill a list with element's attributes

Parameters:
destThe destination list
virtual void* getObject ( const String name) const [inline, virtual]

Get a pointer to this object

Reimplemented from GenObject.

References GenObject::getObject().

const char* getText ( ) const

Get the text of this XML element

Returns:
Pointer to the text of this XML element or 0
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:
listThe list to be searched for the given parameter
stoleTrue to release parameter ownership (defaults to false)
nameParameter name (defaults to 'xml')
valueOptional 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
bool hasAttribute ( const char *  name,
const char *  value 
) const

Check if an attribute with the given name and value exists

Parameters:
nameAttribute's name
valueAttribute's value
Returns:
True/False
bool hasChild ( const char *  name) [inline]

Check if this element has a given child

Parameters:
nameOptional 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:
typeChild's type to find
Returns:
True if this element has the desired child

References XMLElement::hasChild().

Referenced by XMLElement::hasChild().

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:
txtText to compare
typeElement type as enumeration
Returns:
True if txt equals the text associated with the given type
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:
textText to compare with
Returns:
False if text is 0 or not equal to name
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
XMLElement* removeChild ( const char *  name = 0)

Find the first child element of this one. Remove it from the children list. If an element is returned, it owns the TiXmlElement pointer. This element must own its TiXmlElement pointer.

Parameters:
nameOptional name of the child
Returns:
Pointer to an XMLElement or 0 if not found
XMLElement* removeChild ( Type  type) [inline]

Find the first child element of this one. Remove it from the children list. If an element is returned, it owns the TiXmlElement pointer. This element must own its TiXmlElement pointer.

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

References XMLElement::removeChild().

Referenced by XMLElement::removeChild().

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

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

Parameters:
nameAttribute's name
valueAttribute'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:
nameAttribute's name
valueAttribute'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:
nameAttribute's name
valueAttribute's value
void toList ( NamedList dest,
const char *  prefix 
)

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

Parameters:
destDestination list
prefixPrefix to add to parameters
virtual const String& toString ( ) const [inline, virtual]

Release memory

Reimplemented from GenObject.

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

Put the element in a buffer

Parameters:
destDestination string
uncloseTrue to leave the tag unclosed

Referenced by XMLElementOut::toBuffer().

Type type ( ) const [inline]

Get the type of this object

Returns:
The type of this object as enumeration
static const char* typeName ( Type  type) [inline, static]

Get the name associated with the given type

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

References TelEngine::lookup().

bool valid ( ) const [inline]

Get the validity of this object

Returns:
True if m_element is non null

Member Data Documentation

TokenDict s_names[] [static]

Associations between XML element name and type


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