#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. | |
Ref | ref () const |
Return a Dv::Xml::Node::Ref object referring to this Node. | |
operator Ref () | |
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 (Dv::Xml::Exception) |
Retrieve attribute value. | |
const Ref | end () const |
Return Ref that points past the last child of this node. | |
std::string | name () const |
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.
|
Default constructor.
|
|
Create an xml::node with a given name.
|
|
Create an xml::node with a given name and content.
|
|
Return a Dv::Xml::Node::Ref object referring to this Node.
|
|
Return a Dv::Xml::Node::Ref object referring to this Node.
|
|
Set attribute value.
|
|
Retrieve attribute value.
|
|
Return Ref that points past the last child of this node.
Definition at line 495 of file node.h. References Dv::Xml::Node::Ref::end(). |
|
|
dvxml-0.1.4 | [19 September, 2003] |