This is an abstraction of an XML element. More...
#include <tag.h>
Inherited by Stanza.
Public Types | |
typedef std::pair< std::string, std::string > | Attribute |
typedef std::list< Attribute > | AttributeList |
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 AttributeList & | attributes () |
virtual const AttributeList & | attributes () const |
virtual TagList & | children () |
virtual const TagList & | children () const |
virtual const std::string | findAttribute (const std::string &name) const |
virtual bool | hasAttribute (const std::string &name, const std::string &value="") const |
virtual Tag * | findChild (const std::string &name) const |
virtual Tag * | findChild (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 Tag * | findChildWithAttrib (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 |
Tag * | parent () const |
virtual StanzaType | type () const |
virtual Tag * | clone () const |
Tag * | findTag (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 } |
This is an abstraction of an XML element.
Definition at line 32 of file tag.h.
typedef std::pair<std::string, std::string> Attribute |
typedef std::list<Attribute> AttributeList |
enum XPathError [protected] |
Tag | ( | ) |
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).
name | The name of the element. | |
cdata | The XML character data of the element. | |
incoming | Indicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true). |
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).
parent | The parent tag. | |
name | The name of the element. | |
cdata | The XML character data of the element. | |
incoming | Indicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true). |
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.
name | The name of the element. | |
attrib | The attribute name. | |
value | The attribute value. | |
incoming | Indicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true). |
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.
parent | The parent tag. | |
name | The name of the element. | |
attrib | The attribute name. | |
value | The attribute value. | |
incoming | Indicates whether tag names, attributes, attribute values, and cdata shall be escaped (false, default) or not (true). |
void addAttribute | ( | const std::string & | name, | |
long | value | |||
) | [virtual] |
void addAttribute | ( | const std::string & | name, | |
int | value | |||
) | [virtual] |
void addAttribute | ( | const std::string & | name, | |
const std::string & | value | |||
) | [virtual] |
virtual void addCData | ( | const std::string & | cdata | ) | [inline, virtual] |
void addChild | ( | Tag * | child | ) | [virtual] |
void addChildCopy | ( | const Tag * | child | ) | [virtual] |
virtual const AttributeList& attributes | ( | ) | const [inline, virtual] |
virtual AttributeList& attributes | ( | ) | [inline, virtual] |
virtual const std::string& cdata | ( | ) | const [inline, virtual] |
virtual const TagList& children | ( | ) | const [inline, virtual] |
virtual TagList& children | ( | ) | [inline, virtual] |
Tag * clone | ( | ) | const [virtual] |
virtual GLOOX_DEPRECATED bool empty | ( | ) | const [inline, virtual] |
Returns whether the Tag is considered empty, i.e. invalid.
const std::string escape | ( | std::string | what | ) | [static] |
Does some fancy escaping. (& --> &, etc).
what | A string to escape. |
const std::string findAttribute | ( | const std::string & | name | ) | const [virtual] |
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.
name | The name of the element to search for. | |
attr | The name of the attribute of the child element. | |
value | The value of the attribute of the child element. |
Tag * findChild | ( | const std::string & | name | ) | const [virtual] |
Tag::TagList findChildren | ( | const std::string & | name | ) | const |
Returns a list of child tags of the current tag with the given name.
name | The name of the tags to look for. |
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.
attr | The name of the attribute of the child element. | |
value | The value of the attribute of the child element. |
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.
expression | An XPath expression to evaluate. |
Tag::TagList findTagList | ( | const std::string & | expression | ) |
Evaluates the given XPath expression and returns the matched Tags.
expression | An XPath expression to evaluate. |
bool hasAttribute | ( | const std::string & | name, | |
const std::string & | value = "" | |||
) | const [virtual] |
virtual bool hasChild | ( | const std::string & | name, | |
const std::string & | attr = "" , |
|||
const std::string & | value = "" | |||
) | const [inline, virtual] |
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.
name | The name of the child element. | |
attr | The name of the attribute of the child element. | |
value | The value of the attribute of the child element. |
virtual bool hasChildWithAttrib | ( | const std::string & | attr, | |
const std::string & | value = "" | |||
) | const [inline, 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.
attr | The name of the attribute of the child element. | |
value | The value of the attribute of the child element. |
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.
name | The name of the child element. | |
cdata | The character data that has to exist in the child element. |
virtual const std::string& name | ( | ) | const [inline, virtual] |
operator bool | ( | ) | const [inline] |
bool operator!= | ( | const Tag & | right | ) | const [inline] |
bool operator== | ( | const Tag & | right | ) | const |
Tag* parent | ( | ) | const [inline] |
const std::string relax | ( | std::string | what | ) | [static] |
Reverses operation of escape(). (& --> &).
what | A string to de-escape. |
void removeChild | ( | Tag * | tag | ) | [inline] |
virtual void setAttributes | ( | const AttributeList & | attributes | ) | [inline, virtual] |
virtual void setCData | ( | const std::string & | cdata | ) | [inline, virtual] |
virtual StanzaType type | ( | ) | const [inline, virtual] |
const std::string xml | ( | ) | const [virtual] |