node: Construction

Top  Previous  Next

Scripts > Class elements and c++ instructions > Interpreted C++ instructions > node / dnode > node: Construction


You can create single nodes with initializing parameters or without:



node(str& xsLabel)

node(str& xsLabel, str& xsValue)


A new node object will be created with a label and a value according to the parameters.



node(const node& xOther)


A reference on the node object xOther will be created. That means, the new node has the same label, value and the same children as the old. If one of the nodes will be changed, the other will change too.



A copy (isolated form the tree) of a node is yielded by:


node           clone()




node nCopy = root_node.bottomLastChild().clone();



To add a node to a tree structure use one of the following functions:


bool        addChildFirst( const node& xNewChild)

bool        addChildLast( const node& xNewChild)

node        add(const str& xsLabel, const str& xsValue)


By the first function the new node becomes the first child node of the node, of which you called addChildFirst. By the call of addChildLast the passed node will become the last child. true is returned, if the insertion was successful.

The third function add can be read as an abbreviation of:


addChildLast( node( xsLabel, xsValue )


that means a new node is created with the label xsLabel and the value xsValue and inserted as the last child node. The new node is returned or node::npos, if the insertion was not successful.


bool        addChildBefore( const node& xnNewChild, const node& xnRefChild)


Inserts the node xnNewChild before the existing child node xnRefChild.

If refChild is null, insert newChild at the end of the list of children.


node        removeChild(const node& xnOldChild)


Removes the child node indicated by xnOldChild from the list of children, and returns it. If xnOldChild is not a child node::npos is returned.



node and dnode behave differently if it is tried, to insert a d/node, which was already inserted in a tree, at another position:


For a node node this is forbidden and you get an error message.


For a dnode knot this operation is a movement: the dnode with its sub-nodes is inserted in the desired place, however, disappears at the old position. This can be quite useful.


The reason for this different behavior is the different memory management: node's are reference-counted internally and dnode's are managed by the XMLDocument externally.




This page belongs to the TextTransformer Documentation

Home  Content  German