gloox
1.0.1
|
#include <tag.h>
Classes | |
class | Attribute |
Public Types | |
typedef std::list< Attribute * > | AttributeList |
Public Member Functions | |
Tag (const std::string &name, const std::string &cdata=EmptyString) | |
Tag (Tag *parent, const std::string &name, const std::string &cdata=EmptyString) | |
Tag (const std::string &name, const std::string &attrib, const std::string &value) | |
Tag (Tag *parent, const std::string &name, const std::string &attrib, const std::string &value) | |
virtual | ~Tag () |
const std::string | xml () const |
bool | setPrefix (const std::string &prefix) |
const std::string & | prefix () const |
const std::string & | prefix (const std::string &xmlns) const |
bool | setXmlns (const std::string &xmlns, const std::string &prefix=EmptyString) |
const std::string & | xmlns () const |
const std::string & | xmlns (const std::string &prefix) const |
bool | addAttribute (Attribute *attr) |
bool | addAttribute (const std::string &name, const std::string &value) |
bool | addAttribute (const std::string &name, int value) |
bool | addAttribute (const std::string &name, long value) |
void | setAttributes (const AttributeList &attributes) |
void | addChild (Tag *child) |
void | addChildCopy (const Tag *child) |
bool | setCData (const std::string &cdata) |
bool | addCData (const std::string &cdata) |
const std::string & | name () const |
const std::string | cdata () const |
const AttributeList & | attributes () const |
const TagList & | children () const |
const std::string & | findAttribute (const std::string &name) const |
bool | hasAttribute (const std::string &name, const std::string &value=EmptyString) const |
Tag * | findChild (const std::string &name) const |
Tag * | findChild (const std::string &name, const std::string &attr, const std::string &value=EmptyString) const |
bool | hasChild (const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const |
Tag * | findChildWithAttrib (const std::string &attr, const std::string &value=EmptyString) const |
bool | hasChildWithAttrib (const std::string &attr, const std::string &value=EmptyString) const |
TagList | findChildren (const std::string &name, const std::string &xmlns=EmptyString) const |
void | removeChild (const std::string &name, const std::string &xmlns=EmptyString) |
void | removeChild (Tag *tag) |
void | removeAttribute (const std::string &attr, const std::string &value=EmptyString, const std::string &xmlns=EmptyString) |
bool | hasChildWithCData (const std::string &name, const std::string &cdata) const |
Tag * | parent () const |
Tag * | clone () const |
const std::string | findCData (const std::string &expression) const |
const Tag * | findTag (const std::string &expression) const |
ConstTagList | findTagList (const std::string &expression) const |
bool | operator== (const Tag &right) const |
bool | operator!= (const Tag &right) const |
operator bool () const |
This is an abstraction of an XML element.
typedef std::list<Attribute*> AttributeList |
Tag | ( | const std::string & | name, |
const std::string & | cdata = EmptyString |
||
) |
Tag | ( | Tag * | parent, |
const std::string & | name, | ||
const std::string & | cdata = EmptyString |
||
) |
Tag | ( | const std::string & | name, |
const std::string & | attrib, | ||
const std::string & | value | ||
) |
bool addAttribute | ( | Attribute * | attr | ) |
Use this function to add a new attribute to the tag. The Tag will become the owner of the Attribute and take care of deletion. If an Attribute with the same name already exists, it will be replaced by the new one.
attr | A pointer to the attribute to add. |
bool addAttribute | ( | const std::string & | name, |
const std::string & | value | ||
) |
Use this function to add a new attribute to the tag.
name | The name of the attribute. |
value | The value of the attribute. |
bool addAttribute | ( | const std::string & | name, |
int | value | ||
) |
Use this function to add a new attribute to the tag. The value is an int
here.
name | The name of the attribute. |
value | The value of the attribute. |
bool addAttribute | ( | const std::string & | name, |
long | value | ||
) |
Use this function to add a new attribute to the tag. The value is a long
here.
name | The name of the attribute. |
value | The value of the attribute. |
bool addCData | ( | const std::string & | cdata | ) |
void addChild | ( | Tag * | child | ) |
void addChildCopy | ( | const Tag * | child | ) |
const Tag::AttributeList & attributes | ( | ) | const |
const std::string cdata | ( | ) | const |
const TagList & children | ( | ) | const |
Tag * clone | ( | ) | const |
const std::string & findAttribute | ( | const std::string & | name | ) | const |
const std::string findCData | ( | const std::string & | expression | ) | const |
Evaluates the given XPath expression and returns the result Tag's character data, if any. If more than one Tag match, only the first one's character data is returned.
expression | An XPath expression to evaluate. |
Tag * findChild | ( | const std::string & | name | ) | const |
Tag * findChild | ( | const std::string & | name, |
const std::string & | attr, | ||
const std::string & | value = EmptyString |
||
) | const |
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. |
TagList findChildren | ( | const std::string & | name, |
const std::string & | xmlns = EmptyString |
||
) | const |
Returns a list of child tags of the current tag with the given name.
name | The name of the tags to look for. |
xmlns | An optional namespace to check for. |
Tag * findChildWithAttrib | ( | const std::string & | attr, |
const std::string & | value = EmptyString |
||
) | const |
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. |
const Tag * findTag | ( | const std::string & | expression | ) | const |
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. |
ConstTagList findTagList | ( | const std::string & | expression | ) | const |
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 = EmptyString |
||
) | const |
bool hasChild | ( | const std::string & | name, |
const std::string & | attr = EmptyString , |
||
const std::string & | value = EmptyString |
||
) | const |
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. |
|
inline |
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. |
|
inline |
|
inline |
|
inline |
bool operator== | ( | const Tag & | right | ) | const |
|
inline |
|
inline |
const std::string & prefix | ( | const std::string & | xmlns | ) | const |
void removeAttribute | ( | const std::string & | attr, |
const std::string & | value = EmptyString , |
||
const std::string & | xmlns = EmptyString |
||
) |
void removeChild | ( | const std::string & | name, |
const std::string & | xmlns = EmptyString |
||
) |
void removeChild | ( | Tag * | tag | ) |
void setAttributes | ( | const AttributeList & | attributes | ) |
Sets the given attributes. Any existing attributes are lost.
attributes | The attributes to set. |
bool setCData | ( | const std::string & | cdata | ) |
bool setPrefix | ( | const std::string & | prefix | ) |
bool setXmlns | ( | const std::string & | xmlns, |
const std::string & | prefix = EmptyString |
||
) |
const std::string xml | ( | ) | const |
const std::string & xmlns | ( | ) | const |
const std::string & xmlns | ( | const std::string & | prefix | ) | const |
Returns the namespace for the given prefix, or the default namespace if prefix
is empty. Namespace declarations in parent tags will be taken into account. Consider the following XML:
<bar/> is in the foobar
namespace, having a prefix of foo. A call to prefix() will return 'foo'. A call to xmlns( "foo" ) or xmlns( prefix() ) will return 'foobar'. A call to xmlns() will also return 'foobar' (it is a shortcut to xmlns( prefix() ).
prefix | The namespace prefix to look up, or an empty string to fetch the default namespace. |