gloox  0.9.9.12
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | List of all members
Tag Class Reference

#include <tag.h>

Inheritance diagram for Tag:
Inheritance graph
[legend]
Collaboration diagram for Tag:
Collaboration graph
[legend]

Public Types

typedef std::pair< std::string,
std::string > 
Attribute
typedef std::list< AttributeAttributeList
typedef std::list< Tag * > TagList

Public Member Functions

GLOOX_DEPRECATED_CTOR Tag ()
 Tag (const std::string &name, const std::string &cdata="", bool incoming=false)
 Tag (Tag *parent, const std::string &name, const std::string &cdata="", bool incoming=false)
 Tag (const std::string &name, const std::string &attrib, const std::string &value, bool incoming=false)
 Tag (Tag *parent, const std::string &name, const std::string &attrib, const std::string &value, bool incoming=false)
virtual ~Tag ()
virtual const std::string xml () const
virtual void addAttribute (const std::string &name, const std::string &value)
virtual void addAttribute (const std::string &name, int value)
virtual void addAttribute (const std::string &name, long value)
virtual void setAttributes (const AttributeList &attributes)
virtual void addChild (Tag *child)
virtual void addChildCopy (const Tag *child)
virtual void setCData (const std::string &cdata)
virtual void addCData (const std::string &cdata)
virtual const std::string & name () const
virtual const std::string & cdata () const
virtual AttributeListattributes ()
virtual const AttributeListattributes () const
virtual TagListchildren ()
virtual const TagListchildren () const
virtual const std::string findAttribute (const std::string &name) const
virtual bool hasAttribute (const std::string &name, const std::string &value="") const
virtual TagfindChild (const std::string &name) const
virtual TagfindChild (const std::string &name, const std::string &attr, const std::string &value="") const
virtual bool hasChild (const std::string &name, const std::string &attr="", const std::string &value="") const
virtual TagfindChildWithAttrib (const std::string &attr, const std::string &value="") const
virtual bool hasChildWithAttrib (const std::string &attr, const std::string &value="") const
TagList findChildren (const std::string &name) const
void removeChild (Tag *tag)
virtual GLOOX_DEPRECATED bool empty () const
bool hasChildWithCData (const std::string &name, const std::string &cdata) const
Tagparent () const
virtual StanzaType type () const
virtual Tagclone () const
TagfindTag (const std::string &expression)
Tag::TagList findTagList (const std::string &expression)
bool operator== (const Tag &right) const
bool operator!= (const Tag &right) const
 operator bool () const

Static Public Member Functions

static const std::string escape (std::string what)
static const std::string relax (std::string what)

Protected Types

enum  XPathError { XPNoError, XPExpectedLeftOperand }

Detailed Description

This is an abstraction of an XML element.

Author
Jakob Schroeter js@ca.nosp@m.maya.nosp@m..net
Since
0.4

Definition at line 32 of file tag.h.

Member Typedef Documentation

typedef std::pair<std::string, std::string> Attribute

An XML element's attribute.

Definition at line 38 of file tag.h.

typedef std::list<Attribute> AttributeList

A list of XML element attributes.

Definition at line 43 of file tag.h.

typedef std::list<Tag*> TagList

A list of Tags.

Definition at line 48 of file tag.h.

Member Enumeration Documentation

enum XPathError
protected

XPath error conditions.

Enumerator:
XPNoError 

No error occured.

XPExpectedLeftOperand 

Operator expected a left-hand operand.

Definition at line 385 of file tag.h.

Constructor & Destructor Documentation

Tag ( )

Creates an empty tag.

Deprecated:
Will be removed in 1.0

Definition at line 29 of file tag.cpp.

Tag ( const std::string &  name,
const std::string &  cdata = "",
bool  incoming = false 
)
explicit

Creates a new tag with a given name (and XML character data, if given).

Parameters
nameThe name of the element.
cdataThe XML character data of the element.
incomingIndicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true).

Definition at line 34 of file tag.cpp.

Tag ( Tag parent,
const std::string &  name,
const std::string &  cdata = "",
bool  incoming = false 
)
explicit

Creates a new tag as a child tag of the given parent, with a given name (and XML character data, if given).

Parameters
parentThe parent tag.
nameThe name of the element.
cdataThe XML character data of the element.
incomingIndicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true).

Definition at line 42 of file tag.cpp.

Tag ( const std::string &  name,
const std::string &  attrib,
const std::string &  value,
bool  incoming = false 
)
explicit

Creates a new tag with a given name and an attribute.

Parameters
nameThe name of the element.
attribThe attribute name.
valueThe attribute value.
incomingIndicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true).
Since
0.9

Definition at line 52 of file tag.cpp.

Tag ( Tag parent,
const std::string &  name,
const std::string &  attrib,
const std::string &  value,
bool  incoming = false 
)
explicit

Creates a new tag as a child tag of the given parent, with a given name and an attribute.

Parameters
parentThe parent tag.
nameThe name of the element.
attribThe attribute name.
valueThe attribute value.
incomingIndicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true).
Since
0.9

Definition at line 60 of file tag.cpp.

~Tag ( )
virtual

Virtual destructor.

Definition at line 71 of file tag.cpp.

Member Function Documentation

void addAttribute ( const std::string &  name,
const std::string &  value 
)
virtual

Use this function to add a new attribute to the tag.

Parameters
nameThe name of the attribute.
valueThe value of the attribute.

Definition at line 217 of file tag.cpp.

void addAttribute ( const std::string &  name,
int  value 
)
virtual

Use this function to add a new attribute to the tag. The value is an int here.

Parameters
nameThe name of the attribute.
valueThe value of the attribute.
Since
0.8

Definition at line 236 of file tag.cpp.

void addAttribute ( const std::string &  name,
long  value 
)
virtual

Use this function to add a new attribute to the tag. The value is a long here.

Parameters
nameThe name of the attribute.
valueThe value of the attribute.
Since
0.9

Definition at line 255 of file tag.cpp.

virtual void addCData ( const std::string &  cdata)
inlinevirtual

Adds the string to the existing XML character data for this Tag.

Parameters
cdataThe additional cdata.

Definition at line 169 of file tag.h.

void addChild ( Tag child)
virtual

Use this function to add a child node to the tag. The Tag will be owned by Tag.

Parameters
childThe node to be inserted.

Definition at line 274 of file tag.cpp.

void addChildCopy ( const Tag child)
virtual

Use this function to add a copy of the given element to the tag.

Parameters
childThe node to be inserted.
Since
0.9

Definition at line 283 of file tag.cpp.

virtual AttributeList& attributes ( )
inlinevirtual

Use this function to manipulate the list of attributes.

Returns
A reference to the list of attributes.

Definition at line 188 of file tag.h.

virtual const AttributeList& attributes ( ) const
inlinevirtual

Use this function to fetch a const list of attributes.

Returns
A constant reference to the list of attributes.

Definition at line 194 of file tag.h.

virtual const std::string& cdata ( ) const
inlinevirtual

Use this function to retrieve the XML character data of an element.

Returns
The cdata the element contains.

Definition at line 182 of file tag.h.

virtual TagList& children ( )
inlinevirtual

Use this function to manipulate the list of child elements.

Returns
A reference to the list of child elements.

Definition at line 200 of file tag.h.

virtual const TagList& children ( ) const
inlinevirtual

Use this function to fetch a const list of child elements.

Returns
A constant reference to the list of child elements.

Definition at line 206 of file tag.h.

Tag * clone ( ) const
virtual

This function creates a deep copy of this Tag.

Returns
An independent copy of the Tag.
Since
0.7

Definition at line 356 of file tag.cpp.

virtual GLOOX_DEPRECATED bool empty ( ) const
inlinevirtual

Returns whether the Tag is considered empty, i.e. invalid.

Returns
True if the Tag is valid, false if not.
Deprecated:
Use operator bool() instead.

Definition at line 295 of file tag.h.

const std::string escape ( std::string  what)
static

Does some fancy escaping. (& –> &, etc).

Parameters
whatA string to escape.
Deprecated:
Will be removed in 1.0.

Definition at line 151 of file tag.cpp.

const std::string findAttribute ( const std::string &  name) const
virtual

This function can be used to retrieve the value of a Tag's attribute.

Parameters
nameThe name of the attribute to look for.
Returns
The value of the attribute if found, an empty string otherwise.

Definition at line 293 of file tag.cpp.

Tag * findChild ( const std::string &  name) const
virtual

This function finds and returns the first element within the child elements of the current tag that has a matching tag name.

Parameters
nameThe name of the element to search for.
Returns
The found Tag, or NULL.

Definition at line 317 of file tag.cpp.

Tag * findChild ( const std::string &  name,
const std::string &  attr,
const std::string &  value = "" 
) const
virtual

This function finds and returns the first element within the child elements of the current tag, that has a certain name, and a certain attribute with a certain value.

Parameters
nameThe name of the element to search for.
attrThe name of the attribute of the child element.
valueThe value of the attribute of the child element.
Returns
The found Tag, or NULL.

Definition at line 325 of file tag.cpp.

Tag::TagList findChildren ( const std::string &  name) const

Returns a list of child tags of the current tag with the given name.

Parameters
nameThe name of the tags to look for.
Returns
A list of tags with the given name.
Note
The tags are still linked to the current Tag and should not be deleted from the TagList.
Since
0.9

Definition at line 371 of file tag.cpp.

Tag * findChildWithAttrib ( const std::string &  attr,
const std::string &  value = "" 
) const
virtual

This function checks whether the Tag has a child element which posesses a given attribute with an optional value. The name of the child element does not matter.

Parameters
attrThe name of the attribute of the child element.
valueThe value of the attribute of the child element.
Returns
The child if found, NULL otherwise.

Definition at line 348 of file tag.cpp.

Tag * findTag ( const std::string &  expression)

Evaluates the given XPath expression and returns the result Tag. If more than one Tag match, only the first one is returned.

Note
Currently, XPath support is somewhat limited. However, it should be useable for basic expressions. For now, see src/tests/xpath/xpath_test.cpp for supported expressions.
Parameters
expressionAn XPath expression to evaluate.
Returns
A matched Tag, or 0.
Since
0.9

Definition at line 388 of file tag.cpp.

Tag::TagList findTagList ( const std::string &  expression)

Evaluates the given XPath expression and returns the matched Tags.

Note
Currently, XPath support is somewhat limited. However, it should be useable for basic expressions. For now, see src/tests/xpath/xpath_test.cpp for supported expressions.
Parameters
expressionAn XPath expression to evaluate.
Returns
A list of matched Tags, or an empty TagList.
Since
0.9

Definition at line 394 of file tag.cpp.

bool hasAttribute ( const std::string &  name,
const std::string &  value = "" 
) const
virtual

Checks whether the tag has a attribute with given name and optional value.

Parameters
nameThe name of the attribute to check for.
valueThe value of the attribute to check for.
Returns
Whether the attribute exists (optionally with the given value).

Definition at line 303 of file tag.cpp.

virtual bool hasChild ( const std::string &  name,
const std::string &  attr = "",
const std::string &  value = "" 
) const
inlinevirtual

This function checks whether the Tag has a child element with a given name, and optionally this child element is checked for having a given attribute with an optional value.

Parameters
nameThe name of the child element.
attrThe name of the attribute of the child element.
valueThe value of the attribute of the child element.
Returns
True if the given child element exists, false otherwise.

Definition at line 250 of file tag.h.

virtual bool hasChildWithAttrib ( const std::string &  attr,
const std::string &  value = "" 
) const
inlinevirtual

This function checks whether the Tag has a child element which posesses a given attribute with an optional value. The name of the child element does not matter.

Parameters
attrThe name of the attribute of the child element.
valueThe value of the attribute of the child element.
Returns
True if any such child element exists, false otherwise.

Definition at line 270 of file tag.h.

bool hasChildWithCData ( const std::string &  name,
const std::string &  cdata 
) const

This function checks whether a child element with given name exists and has XML character data that equals the given cdata string.

Parameters
nameThe name of the child element.
cdataThe character data that has to exist in the child element.
Returns
True if a child element with given cdata exists, false otherwise.

Definition at line 339 of file tag.cpp.

virtual const std::string& name ( ) const
inlinevirtual

Use this function to retrieve the name of an element.

Returns
The name of the tag.

Definition at line 176 of file tag.h.

operator bool ( ) const
inline

Returns true if the Tag is valid, false otherwise.

Definition at line 365 of file tag.h.

bool operator!= ( const Tag right) const
inline

Checks two Tags for inequality. Order of attributes and child tags does matter.

Parameters
rightThe Tag to check against the current Tag.
Since
0.9

Definition at line 360 of file tag.h.

bool operator== ( const Tag right) const

Checks two Tags for equality. Order of attributes and child tags does matter.

Parameters
rightThe Tag to check against the current Tag.
Since
0.9

Definition at line 81 of file tag.cpp.

Tag* parent ( ) const
inline

Returns the tag's parent Tag.

Returns
The Tag above the current Tag. May be 0.

Definition at line 310 of file tag.h.

const std::string relax ( std::string  what)
static

Reverses operation of escape(). (& –> &).

Parameters
whatA string to de-escape.
Deprecated:
Will be removed in 1.0.

Definition at line 173 of file tag.cpp.

void removeChild ( Tag tag)
inline

Removes the given Tag from the list of child Tags.

Parameters
tagThe Tag to delete from the list of child Tags.
Note
The Tag tag is not deleted.

Definition at line 288 of file tag.h.

virtual void setAttributes ( const AttributeList attributes)
inlinevirtual

Sets the given attributes. Any existing attributes are lost.

Parameters
attributesThe attributes to set.
Since
0.9

Definition at line 143 of file tag.h.

virtual void setCData ( const std::string &  cdata)
inlinevirtual

Sets the XML character data for this Tag.

Parameters
cdataThe new cdata.

Definition at line 162 of file tag.h.

virtual StanzaType type ( ) const
inlinevirtual

Returns the stanza type.

Returns
The type of the stanza.

Definition at line 316 of file tag.h.

const std::string xml ( ) const
virtual

This function can be used to retrieve the complete XML of a tag as a string. It includes all the attributes, child nodes and character data.

Returns
The complete XML.

Definition at line 97 of file tag.cpp.


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