Yate
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
XmlElement Class Reference

Xml Element. More...

#include <yatexml.h>

Inheritance diagram for XmlElement:
XmlChild XmlParent GenObject

Public Member Functions

 XmlElement (const NamedList &element, bool empty, XmlParent *parent=0)
 
 XmlElement (const char *name, bool complete=true)
 
 XmlElement (const char *name, const char *value, bool complete=true)
 
 XmlElement (const XmlElement &orig)
 
virtual ~XmlElement ()
 
const char * tag () const
 
bool isDefaultNs () const
 
const StringunprefixedTag () const
 
void setUnprefixedTag (const String &s)
 
const StringgetTag () const
 
bool getTag (const String *&tag, const String *&ns) const
 
virtual XmlElementxmlElement ()
 
virtual XmlElementelement ()
 
virtual XmlSaxParser::Error addChild (XmlChild *child)
 
virtual XmlChildremoveChild (XmlChild *child, bool delObj=true)
 
virtual void setCompleted ()
 
bool completed () const
 
bool empty () const
 
XmlElementparent () const
 
virtual XmlParentgetParent ()
 
virtual void setParent (XmlParent *parent)
 
virtual const StringgetName () const
 
virtual const NamedListgetElement () const
 
const ObjListgetChildren () const
 
void clearChildren ()
 
const NamedListinheritedNs () const
 
void setInheritedNs (const XmlElement *xml=0, bool inherit=true)
 
void addInheritedNs (const NamedList &list)
 
XmlElementpop ()
 
virtual const StringtoString () const
 
void toString (String &dump, bool escape=true, const String &indent=String::empty(), const String &origIndent=String::empty(), bool completeOnly=true, const String *auth=0) const
 
XmlElementfindFirstChild (const String *name=0, const String *ns=0, bool noPrefix=true) const
 
XmlElementfindFirstChild (const String &name, const String *ns=0, bool noPrefix=true) const
 
XmlElementfindNextChild (const XmlElement *prev=0, const String *name=0, const String *ns=0, bool noPrefix=true) const
 
XmlElementfindNextChild (const String &name, const XmlElement *prev=0, const String *ns=0, bool noPrefix=true) const
 
const StringchildText (const String &name, const String *ns=0, bool noPrefix=true) const
 
XmlChildgetFirstChild ()
 
const StringgetText () const
 
XmlTextsetText (const char *text)
 
void addText (const char *text)
 
const NamedListattributes () const
 
unsigned int copyAttributes (NamedList &list, const String &prefix) const
 
void setAttributes (NamedList &list, const String &prefix, bool skipPrefix=true)
 
void setAttribute (const String &name, const char *value)
 
void setAttributeValid (const String &name, const char *value)
 
const char * attribute (const String &name) const
 
StringgetAttribute (const String &name) const
 
bool hasAttribute (const String &name, const String &value) const
 
void removeAttribute (const String &name)
 
Stringxmlns () const
 
StringxmlnsAttribute (const String &name) const
 
bool hasXmlns (const String &ns) const
 
bool setXmlns (const String &name=String::empty(), bool addAttr=false, const String &value=String::empty())
 
- Public Member Functions inherited from XmlChild
 XmlChild ()
 
virtual XmlCommentxmlComment ()
 
virtual XmlCDataxmlCData ()
 
virtual XmlTextxmlText ()
 
virtual XmlDeclarationxmlDeclaration ()
 
virtual XmlDoctypexmlDoctype ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
virtual void * getObject (const String &name) const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 
- Public Member Functions inherited from XmlParent
 XmlParent ()
 
virtual ~XmlParent ()
 
virtual XmlDocumentdocument ()
 
virtual XmlFragmentfragment ()
 
XmlChildaddChildSafe (XmlChild *child)
 
virtual void reset ()
 
bool hasChildren () const
 

Static Public Member Functions

static bool isXmlns (const String &str)
 
static XmlElementparam2xml (NamedString *param, const String &tag, bool copyXml=false)
 
static NamedStringxml2param (XmlElement *xml, const String *tag, bool copyXml=false)
 
static void xml2param (NamedList &list, XmlElement *parent, const String *tag, bool copyXml=false)
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Static Public Attributes

static const String s_ns
 
static const String s_nsPrefix
 

Detailed Description

Xml Element.

Xml Element from a Xml document

Constructor & Destructor Documentation

XmlElement ( const NamedList element,
bool  empty,
XmlParent parent = 0 
)

Constructor

Parameters
elementThe NamedList name represent the element name and the param the attributes
emptyFalse if has children
parentThe parent of this element
XmlElement ( const char *  name,
bool  complete = true 
)

Constructor. Creates a new complete and empty element

Parameters
nameThe name of the element
completeFalse to build an incomplete element
XmlElement ( const char *  name,
const char *  value,
bool  complete = true 
)

Constructor. Create a new element with a text child

Parameters
nameThe name of the element
valueElement text child value
completeFalse to build an incomplete element
XmlElement ( const XmlElement orig)

Copy constructor

Parameters
origOriginal XmlElement
virtual ~XmlElement ( )
virtual

Destructor

Member Function Documentation

virtual XmlSaxParser::Error addChild ( XmlChild child)
virtual

Append a new child of this element

Parameters
childThe child to append

Implements XmlParent.

void addInheritedNs ( const NamedList list)

Add inherited namespaces from a list

Parameters
listThe list of namespaces
void addText ( const char *  text)

Add a text child

Parameters
textNon empty text to add
const char* attribute ( const String name) const
inline

Obtain an attribute value for the given name

Parameters
nameThe name of the attribute
Returns
Attribute value

References NamedList::getValue().

const NamedList& attributes ( ) const
inline

Retrieve the list of attributes

Returns
Element attributes
const String* childText ( const String name,
const String ns = 0,
bool  noPrefix = true 
) const
inline

Retrieve a child's text

Parameters
nameName (tag) of the child
nsOptional child namespace
noPrefixTrue to compare the tag without namespace prefix, false to include namespace prefix when comparing the given tag. This parameter is ignored ns is not 0
Returns
Pointer to child's text, 0 if the child was not found

References XmlElement::findFirstChild(), and XmlElement::getText().

void clearChildren ( )
inlinevirtual

Helper method to clear the children list

Reimplemented from XmlParent.

References XmlFragment::clearChildren().

bool completed ( ) const
inline
Returns
True if this element is completed

Referenced by XmlElement::pop().

unsigned int copyAttributes ( NamedList list,
const String prefix 
) const

Copy element attributes to a list of parameters

Parameters
listDestination list
prefixPrefix to be added to each attribute name
Returns
The number of attributes added to the destination list
virtual XmlElement* element ( )
inlinevirtual

Get an XmlElement from this XmlParent

Returns
This object

Reimplemented from XmlParent.

bool empty ( ) const
inline
Returns
True if this element is empty
XmlElement* findFirstChild ( const String name = 0,
const String ns = 0,
bool  noPrefix = true 
) const
inline

Find the first XmlElement child of this XmlElement

Parameters
nameOptional name of the child
nsOptional child namespace
noPrefixTrue to compare the tag without namespace prefix, false to include namespace prefix when comparing the given tag. This parameter is ignored if name is 0 or ns is not 0
Returns
The first child element meeting the requested conditions

References XmlFragment::findElement(), and XmlElement::getChildren().

Referenced by XmlElement::childText(), XmlElement::findNextChild(), and XmlElement::pop().

XmlElement* findFirstChild ( const String name,
const String ns = 0,
bool  noPrefix = true 
) const
inline

Find the first XmlElement child of this XmlElement

Parameters
nameName of the child
nsOptional child namespace
noPrefixTrue to compare the tag without namespace prefix, false to include namespace prefix when comparing the given tag. This parameter is ignored if name is 0 or ns is not 0
Returns
The first child element meeting the requested conditions

References XmlFragment::findElement(), and XmlElement::getChildren().

XmlElement* findNextChild ( const XmlElement prev = 0,
const String name = 0,
const String ns = 0,
bool  noPrefix = true 
) const
inline

Finds next XmlElement child of this XmlElement

Parameters
prevPrevious child
nameOptional name of the child
nsOptional child namespace
noPrefixTrue to compare the tag without namespace prefix, false to include namespace prefix when comparing the given tag. This parameter is ignored if name is 0 or ns is not 0
Returns
The next found child if prev exists else the first

References ObjList::find(), XmlFragment::findElement(), XmlElement::findFirstChild(), XmlElement::getChildren(), and ObjList::skipNext().

Referenced by XmlElement::findNextChild().

XmlElement* findNextChild ( const String name,
const XmlElement prev = 0,
const String ns = 0,
bool  noPrefix = true 
) const
inline

Finds next XmlElement child of this XmlElement

Parameters
nameName of the child
prevPrevious child
nsOptional child namespace
noPrefixTrue to compare the tag without namespace prefix, false to include namespace prefix when comparing the given tag. This parameter is ignored if name is 0 or ns is not 0
Returns
The next found child if prev exists else the first

References XmlElement::findNextChild().

String* getAttribute ( const String name) const
inline

Obtain an attribute value for the given name

Parameters
nameThe name of the attribute
Returns
String pointer or 0 if not found

References NamedList::getParam().

Referenced by XmlElement::hasAttribute().

const ObjList& getChildren ( ) const
inlinevirtual

Helper method to obtain the children list

Returns
The children list

Reimplemented from XmlParent.

References XmlFragment::getChildren().

Referenced by XmlElement::findFirstChild(), and XmlElement::findNextChild().

virtual const NamedList& getElement ( ) const
inlinevirtual
Returns
The held element
XmlChild* getFirstChild ( )

Get first XmlChild of this XmlElement

Returns
The first XmlChild found.
virtual const String& getName ( ) const
inlinevirtual
Returns
The name of this element
virtual XmlParent* getParent ( )
inlinevirtual
Returns
The parent of this element
const String& getTag ( ) const
inline

Retrieve the element's tag (without prefix)

Returns
Element tag

References NamedString::name().

bool getTag ( const String *&  tag,
const String *&  ns 
) const

Retrieve the element's tag (without prefix) and namespace

Parameters
tagPointer to element tag
nsPointer to element's namespace (may be 0 for unprefixed tags)
Returns
True if a namespace was found for the element tag or the tag is not prefixed
const String& getText ( ) const
Returns
The first XmlText found in this XmlElement children

Referenced by XmlElement::childText().

bool hasAttribute ( const String name,
const String value 
) const
inline

Check if the element has an attribute with a requested value

Parameters
nameThe name of the attribute
valueThe value to check
Returns
True if the element has an attribute with the requested value

References XmlElement::getAttribute().

bool hasXmlns ( const String ns) const
inline

Verify if this element belongs to the given namespace

Parameters
nsThe namespace to compare with
Returns
True if this element belongs to the given namespace

References XmlElement::xmlns().

const NamedList* inheritedNs ( ) const
inline

Retrieve the list of inherited namespaces

Returns
The list of inherited namespaces (or 0)
bool isDefaultNs ( ) const
inline

Check if this element must be processed in the default namespace (its tag is not prefixed)

Returns
True if this element must be processed in the default namespace
static bool isXmlns ( const String str)
inlinestatic

Check if a string represents a namespace attribute name

Parameters
strThe string to check
Returns
True if the given string is the default namespace attribute name or a namespace attribute name prefix

References XmlElement::s_ns, XmlElement::s_nsPrefix, and String::startsWith().

static XmlElement* param2xml ( NamedString param,
const String tag,
bool  copyXml = false 
)
static

Build an XML element from a list parameter. Parameter name will be set in a 'name' attribute. Parameter value will be set in a 'value' attribute Handle NamedPointer parameters carrying DataBlock, NamedList and XmlElement objects (a 'type' attribute is added to the created element). DataBlock: Encode using BASE64 and add it as element text NamedList: The name is added as element text. The function is called again for each list parameter XmlElement: Added as child to newly created element

Parameters
paramThe parameter to convert
tagXmlElement tag
copyXmlTrue to copy XmlElement objects instead of just remove them from the parameter
Returns
XmlElement pointer or 0 on failure
XmlElement* parent ( ) const
inline

Retrieve an XmlElement parent of this one

Returns
XmlElement pointer or 0

References XmlParent::element().

XmlElement* pop ( )
inline

Extract the first child element

Returns
XmlElement pointer or 0

References XmlElement::completed(), XmlElement::findFirstChild(), and XmlFragment::removeChild().

void removeAttribute ( const String name)
inline

Remove an attribute

Parameters
nameAttribute name

References NamedList::clearParam().

Referenced by XmlElement::setAttributeValid().

virtual XmlChild* removeChild ( XmlChild child,
bool  delObj = true 
)
virtual

Remove a child

Parameters
childThe child to remove
delObjTrue to delete the object
Returns
XmlChild pointer if found and not deleted

Implements XmlParent.

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

Add or replace an attribute

Parameters
nameAttribute name
valueAttribute value

References NamedList::setParam().

void setAttributes ( NamedList list,
const String prefix,
bool  skipPrefix = true 
)

Set element attributes from a list of parameters

Parameters
listList of attributes
prefixAdd only the attributes that start with this prefix. = If NULL, it will set as attributes the whole parameter list
skipPrefixSkip over the prefix when building attribute name
void setAttributeValid ( const String name,
const char *  value 
)
inline

Add or replace an attribute. Clears it if value is empty

Parameters
nameAttribute name
valueAttribute value

References TelEngine::null(), XmlElement::removeAttribute(), and NamedList::setParam().

virtual void setCompleted ( )
inlinevirtual

Notification for this element that is complete

void setInheritedNs ( const XmlElement xml = 0,
bool  inherit = true 
)

Set inherited namespaces from a given element. Reset them anyway

Parameters
xmlThe source element used to set inherited namespaces
inheritCopy element's inherited namespaces if it doesn't have a parent
virtual void setParent ( XmlParent parent)
virtual

Set this element's parent. Update inherited namespaces

Returns
The parent of this element

Reimplemented from XmlChild.

XmlText* setText ( const char *  text)

Set text for first XmlText element found in this XmlElement's children If child text element does not exist, create it and append it to the element's children.

Parameters
textText to set to the XmlElement. If null, the first found XmlText element will be deleted.
Returns
The set XmlText if text was set, null if an XmlText was deleted
void setUnprefixedTag ( const String s)

Set element's unprefixed tag, don't change namespace prefix

Parameters
sNew element's tag
bool setXmlns ( const String name = String::empty(),
bool  addAttr = false,
const String value = String::empty() 
)

Set the element's namespace

Parameters
nameThe namespace name (element prefix). Can be the default namespace attribute name (empty means the default one)
addAttrTrue to add a non empty, not repeating, namespace attribute to the list
valueNamespace value (ignored if addAttr is false)
Returns
True on success, false if another namespace exists with the same value
const char* tag ( ) const
inline

Retrieve the element's tag

Returns
The element's tag
virtual const String& toString ( ) const
inlinevirtual

Retrieve the element tag

Returns
The element tag

Reimplemented from GenObject.

void toString ( String dump,
bool  escape = true,
const String indent = String::empty(),
const String origIndent = String::empty(),
bool  completeOnly = true,
const String auth = 0 
) const

Build (append to) a String from this XmlElement

Parameters
dumpThe destination string
escapeTrue if the attributes values need to be escaped
indentSpaces for output
origIndentOriginal indent
completeOnlyTrue to build only if complete
authOptional list of tag and attribute names to be replaced with '***'. This parameter can be used when the result will be printed to output to avoid printing authentication data to output. The array must end with an empty string
const String& unprefixedTag ( ) const
inline

Retrieve the element's tag unprefixed (namespace prefix removed)

Returns
The element's tag unprefixed

References NamedString::name().

static NamedString* xml2param ( XmlElement xml,
const String tag,
bool  copyXml = false 
)
static

Build a list parameter from xml element See param2xml for more info

Parameters
xmlThe XML element to process
tagChild XmlElement tag to handle
copyXmlTrue to copy XmlElement objects instead of just remove them from parent
Returns
NamedString pointer or 0 on failure
static void xml2param ( NamedList list,
XmlElement parent,
const String tag,
bool  copyXml = false 
)
static

Build and add list parameters from XML element children. Each parameter will be taken from 'name' and 'value' attributes. See param2xml for more info

Parameters
listDestination list
parentThe XML element to process
tagChild XmlElement tag to handle
copyXmlTrue to copy XmlElement objects instead of just remove them from parent
virtual XmlElement* xmlElement ( )
inlinevirtual

Get an XmlElement from this XmlChild

Returns
This object

Reimplemented from XmlChild.

String* xmlns ( ) const
inline

Retrieve the element's namespace

Returns
Element's namespace or 0 if not found

References XmlElement::s_ns, XmlElement::s_nsPrefix, and XmlElement::xmlnsAttribute().

Referenced by XmlElement::hasXmlns().

String* xmlnsAttribute ( const String name) const

Retrieve a namespace attribute. Search in parent or inherited for it

Returns
String pointer or 0 if not found

Referenced by XmlElement::xmlns().

Member Data Documentation

const String s_ns
static

Default namespace attribute name

Referenced by XmlElement::isXmlns(), and XmlElement::xmlns().

const String s_nsPrefix
static

Namespace attribute name perfix

Referenced by XmlElement::isXmlns(), and XmlElement::xmlns().


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