#include <node.h>
Public Member Functions | |
Node () | |
Default constructor. | |
Node (const std::string &name) | |
Create an xml::node with a given name. | |
Node (const std::string &name, const std::string &content) | |
Create an xml::node with a given name and content. | |
template<typename T> | |
Node (const std::string &name, const T &c) | |
Ref | ref () const |
Return a Dv::Xml::Node::Ref object referring to this Node. | |
Ref | ref () |
Return a Dv::Xml::Node::Ref object referring to this Node. | |
operator Node::Ref () | |
Return a Dv::Xml::Node::Ref object referring to this Node. | |
operator Node::Ref () const | |
Return a Dv::Xml::Node::Ref object referring to this Node. | |
AttributeReference | operator[] (const std::string &name) |
Set attribute value. | |
const std::string | operator() (const std::string &name) const throw (Exception) |
Retrieve attribute value. | |
const Ref | end () const |
Return Ref that points past the last child of this node. | |
std::string | name () const |
| |
Node & | add (const Node::Ref &ref) |
Add another node as a child to this node. | |
Node & | add (const std::string &name) |
Add a new node as a child to this node. | |
Node & | add (const std::string &name, const std::string &contents) |
Add a new text node as a child to this node. | |
template<typename T> | |
Node & | add (const std::string &name, const T &contents) |
Add a new text node as a child to this node. | |
Classes | |
class | AttributeReference |
Auxiliary class for attribute access. More... | |
class | Ref |
A reference to an xml::node object. More... |
There are two classes:
The intention is that Dv::Xml::Node is only used for "roots" in XML tree structures, as in
Dv::Xml::Node node("rootlabel");
For all other operations, Dv::Xml::Node::Ref should be used. A strange feature is that Dv::Xml::Node::Ref::operator* returns a reference to itself. The reason is that returning a reference to a Dv::Xml::Node would involve copying the underlying xml::node. On the other hand, returning a reference to the underlying xml::node would imply that the convenient member functions of Dv::Xml::Node::Ref would not be available on the result of Dv::Xml::Node::Ref::operator* .
For convenience, some Dv::Xml::Node::Ref operations are also available on Dv::Xml::Node, either by direct delegation (e.g. Dv::Xml::Node::operator[], Dv::Xml::Node::operator()) or via a user-defined convertor that converst a Dv::Xml::Node to a Dv::Xml::Node::Ref referring to this node.
The main difference with the underlying xmlwrapp interface is that many operations are available through expressions. E.g. (n/"login"/"name")("first_name"), with n a Dv::Xml::Node of Dv::Xml::Node::Ref object, * refers to the first_name attribute of the node obtained from n by taking the first "login" child and then the first "name" child.
Intuitively, for a Dv::Xml::Node::Ref n, n/"label" returns a Dv::Xml::Node::Ref referring to the first child node with "label" as name. The increment operator returns the next child with the same name. E.g.
Dv::Xml::Node::Ref n; .. Dv::Xml::Node::Ref c(n/"label"); ++c // refer to 2nd child of n with name "label"
The > operator can be used to create new child nodes. E.g. n>"label" returns a new child of n with name "label". The same operator also works with a Dv::Xml::Node argument.
Dv::Xml::Node::Ref n; Dv::Xml::Node::Ref c; (n >> c) // attach a copy of c as a child to n
Attributes can be set and accessed using operator[] and operator() respectively.
Dv::Xml::Node::Ref n; n["first_name"] = "blabla"; // set attribute if (n("first_name") != "blabla") // obtain attribute value throw std::logic_error("BUG");
The text content of a Dv::Xml::Node::Ref can be obtained by a conversion (to std::string) operator. Assigning a std::string to a Dv::Xml::Node::Ref has the same effect as xml::node::set_content().
Definition at line 89 of file node.h.
Dv::Xml::Node::Node | ( | ) | [inline] |
Dv::Xml::Node::Node | ( | const std::string & | name | ) | [inline, explicit] |
Dv::Xml::Node::Node | ( | const std::string & | name, | |
const std::string & | content | |||
) | [inline] |
Dv::Xml::Node::Node | ( | const std::string & | name, | |
const T & | c | |||
) | [inline, explicit] |
Ref Dv::Xml::Node::ref | ( | ) | const [inline] |
Return a Dv::Xml::Node::Ref object referring to this Node.
Definition at line 469 of file node.h.
Referenced by end(), operator Node::Ref(), operator()(), Dv::Xml::operator/(), Dv::Xml::operator>>(), and operator[]().
Ref Dv::Xml::Node::ref | ( | ) | [inline] |
Dv::Xml::Node::operator Node::Ref | ( | ) | [inline] |
Return a Dv::Xml::Node::Ref object referring to this Node.
Definition at line 479 of file node.h.
References ref().
Dv::Xml::Node::operator Node::Ref | ( | ) | const [inline] |
Return a Dv::Xml::Node::Ref object referring to this Node.
Definition at line 482 of file node.h.
References ref().
AttributeReference Dv::Xml::Node::operator[] | ( | const std::string & | name | ) | [inline] |
Set attribute value.
name | key of attribute |
Dv::Xml::Node::Ref n; .. n["name"] = "fred"; std::cout << n["name"] << std::endl;
Definition at line 496 of file node.h.
References ref().
const std::string Dv::Xml::Node::operator() | ( | const std::string & | name | ) | const throw (Exception) [inline] |
Retrieve attribute value.
name | key of attribute |
Dv::Xml::Exception | if this node has no attribute for key "name". |
const Ref Dv::Xml::Node::end | ( | ) | const [inline] |
Return Ref that points past the last child of this node.
Definition at line 510 of file node.h.
References Dv::Xml::Node::Ref::end(), and ref().
std::string Dv::Xml::Node::name | ( | ) | const [inline] |
Definition at line 513 of file node.h.
Referenced by add(), operator()(), Dv::Xml::operator/(), and Dv::Xml::operator>>().
Add another node as a child to this node.
ref | reference to node to add |
Referenced by Dv::Sql::xml_add(), and Dv::Sql::xml_add_member().
Node& Dv::Xml::Node::add | ( | const std::string & | name | ) | [inline] |
Node& Dv::Xml::Node::add | ( | const std::string & | name, | |
const std::string & | contents | |||
) | [inline] |
Node& Dv::Xml::Node::add | ( | const std::string & | name, | |
const T & | contents | |||
) | [inline] |
Add a new text node as a child to this node.
name | of the new node to add as a child | |
contents | of the new node to add as a child |
Definition at line 556 of file node.h.
References name(), Node(), and Dv::Util::tostring().
dvxml-0.1.7 | [ 7 January, 2008] |