![]() |
Plus | - Minimal XML for C++ | (Version 0.9.2) | Giancarlo Niccolai |
#include <mxml_node.h>
Inheritance diagram for MXML::Node:
Public Types | |
typedef __iterator< Node > | iterator |
typedef __iterator< const Node > | const_iterator |
typedef __deep_iterator< Node > | deep_iterator |
typedef __deep_iterator< const Node > | const_deep_iterator |
typedef __find_iterator< Node > | find_iterator |
typedef __find_iterator< const Node > | const_find_iterator |
typedef __path_iterator< Node > | path_iterator |
typedef __path_iterator< const Node > | const_path_iterator |
enum | type { typeTag = 0, typeXMLDecl, typeComment, typePI, typeDirective, typeData, typeDocument, typeFakeClosing } |
Node types. More... | |
Public Member Functions | |
Node (std::istream &in, const int style=0, const int line=1, const int pos=0) throw ( MalformedError ) | |
Deserializes a node Reads a node from an XML file at current position. | |
Node (const type tp, const std::string &name="", const std::string &data="") | |
Node (Node &) | |
Copy constructor. | |
~Node () | |
Deletes the node. | |
const type | nodeType () const |
Returns the type of this node. | |
const std::string | name () const |
Returns current name of the node. | |
const std::string | data () const |
Returns the data element of the node. | |
void | name (const std::string &new_name) |
Change name of the node. | |
void | data (const std::string &new_value) |
Change data of the node. | |
void | addAttribute (Attribute *attrib) |
Adds a new attribute at the end of the attribute list. | |
const std::string | getAttribute (const std::string name) const throw ( NotFoundError ) |
Gets the value of the given attribute. | |
void | setAttribute (const std::string name, const std::string value) throw ( NotFoundError ) |
Sets the value of a given attribute. | |
bool | hasAttribute (const std::string name) const |
Returns true if the node has a given attribute. | |
void | unlink () |
Detaches current node from its parent and brothers. | |
Node * | unlinkComplete () |
Detaches current node from all the adiacents node. | |
void | Node::removeChild (Node *child) throw ( NotFoundError ) |
Removes a child from the children list. | |
Node * | parent () const |
Node * | child () const |
Node * | next () const |
Node * | prev () const |
Node * | lastChild () const |
void | addBelow (Node *) |
void | insertBelow (Node *) |
void | insertBefore (Node *) |
void | insertAfter (Node *) |
int | Node::depth () const |
Returns the depth of the path leading to this node. | |
std::string | Node::path () const |
Returns a symbolic path leading to the node. | |
Node * | clone () |
virtual void | write (std::ostream &out, const int style) const |
Writes the node on a stream. | |
iterator | begin () |
iterator | end () |
const_iterator | const_begin () const |
const_iterator | const_end () |
deep_iterator | deep_begin () |
find_iterator | find (std::string name, std::string attrib="", std::string valatt="", std::string data="") |
Find one or more with specific characteristics. | |
path_iterator | find_path (std::string path) |
Recursive node path find iterator. | |
Protected Member Functions | |
void | nodeIndent (std::ostream &out, const int depth, const int style) const |
void | readData (std::istream in, const int iStyle) |
Private Attributes | |
type | m_type |
std::string | m_name |
std::string | m_data |
AttribList | m_attrib |
AttribList::iterator | m_lastFound |
Node * | m_parent |
Node * | m_child |
Node * | m_last_child |
Node * | m_next |
Node * | m_prev |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Node types. This enum describes the kind of node that is held inside this object.
|
|
Deserializes a node Reads a node from an XML file at current position. In case of error Throws an MXML::IOError or MXML::MalformedError.
|
|
|
|
Copy constructor. See clone() |
|
Deletes the node. All the attributes in the attribute list are deleted also, as well as the children of the node. To avoid deleting the children do an unlinkComplete of the parent after having got the first child; then insert it below or after another node, or iterate through an addBelow():
|
|
Adds a new attribute at the end of the attribute list.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Change data of the node. The user can also set the data for a node that should not have it (i.e. an XMLdecl type), but the data will be ignored by the system.
|
|
Returns the data element of the node. If the name is not defined, it returns an empty string. |
|
|
|
|
|
Find one or more with specific characteristics. This function returns an iterator that iterates over all the nodes below this one that matches the given criteria:
In case one or more of the elements is to be ignored, it just set the corresponding parameter to an empty string (""); if all the parameters are set to an empty string, the iterator will iterate over all the nodes below this one. The search is done deeply: all the nodes below this one that matches the search criteria are returned, regardless of their level and distance from this node. In example, to search for all the nodes named "mynode" having the word "good" in their data, perform the following scan:
MXML::find_iterator iter = currentNode->find( "mynode", "", "", "good" ); while( iter != currentNode->end() ) { std::out << "Data inside node MYNODE: " << endl; std::cout << (*iter)->data() << endl; iter++; }
|
|
Recursive node path find iterator.
|
|
Gets the value of the given attribute. If the attribute is present, its value is returned. If it is not present, an MXML::NotFoundError error is thrown.
|
|
Returns true if the node has a given attribute. The found attribute is cached, so if you make this method follow by a getAttribute, the whole operation is done efficiently: ... if ( node.hasAttribute( "position" ) ) pos = node.getAttribute( "position"); else { pos = "0"; node.addAttribute( new Attribute( "position", pos ) ); } ...
|
|
|
|
|
|
|
|
|
|
Change name of the node. If the node should not have a name (i.e. comments) this value will be ignored by the system.
|
|
Returns current name of the node. If the name is not defined, it returns an empty string. |
|
|
|
Returns the depth of the path leading to this node. ...Or how many levels are above this node. Can be called also for nodes that have not a valid symbolic path. |
|
Returns a symbolic path leading to the node. A Node path is the the list of all the ancestor node names, plus the name of the current node, separated by a "/" sign. So, if you have a doucument like: <root> <item>an item</item> </root> the path to item will "/root/item". Node paths have not to be unique (two nodes can have the same name and be brothers). A node can also have an empty path if it has not a name, or if it is a child of nodes that have not a name. I.e. data nodes and comments have not a path.
|
|
Removes a child from the children list. The child is not deleted; an error is thrown if the parameter is not a child of this object.
|
|
|
|
Returns the type of this node.
|
|
|
|
|
|
|
|
Sets the value of a given attribute. This is a shortcut instead of searching for an attribute in the list returned by attributes() method and setting its value.
|
|
Detaches current node from its parent and brothers. The node still retain its children though. |
|
Detaches current node from all the adiacents node. Be sure to have a reference to the children nodes, or the whole children hierarcy will be lost (causing a memory leak). The ideal is to use a Node list to save the old children; the list can then be added to other nodes children, like that: ... Node *kids; kids = myNode->unlinkComplete(); targetNode.insertBelow( kids ); ...
|
|
Writes the node on a stream. This function is usually called by MXML::Document::write(), or by the << operator (in class MXML::Element), use the latter only for debug.
Implements MXML::Element. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|