Rudiments
Public Member Functions | Static Public Member Functions | List of all members
xmldomnode Class Reference

Public Member Functions

 xmldomnode (xmldom *dom, xmldomnode *nullnode)
 
 xmldomnode (xmldom *dom, xmldomnode *nullnode, xmldomnodetype type, const char *name, const char *value)
 
 ~xmldomnode ()
 
void cascadeOnDelete ()
 
void dontCascadeOnDelete ()
 
xmldomnodetype getType () const
 
const char * getName () const
 
const char * getValue () const
 
xmldomgetTree () const
 
xmldomnodegetParent () const
 
uint64_t getPosition () const
 
xmldomnodegetPreviousSibling () const
 
xmldomnodegetPreviousTagSibling () const
 
xmldomnodegetPreviousTagSibling (const char *name) const
 
xmldomnodegetPreviousTagSibling (const char *name, const char *attributename, const char *attributevalue) const
 
xmldomnodegetNextSibling () const
 
xmldomnodegetNextTagSibling () const
 
xmldomnodegetNextTagSibling (const char *name) const
 
xmldomnodegetNextTagSibling (const char *name, const char *attributename, const char *attributevalue) const
 
xmldomnodegetNextTagSiblingInSet (const char *const *set) const
 
uint64_t getChildCount () const
 
xmldomnodegetChild (const char *name) const
 
xmldomnodegetChild (uint64_t position) const
 
xmldomnodegetChild (const char *name, const char *attributename, const char *attributevalue) const
 
xmldomnodegetFirstTagChild () const
 
xmldomnodegetFirstTagChild (const char *name) const
 
xmldomnodegetFirstTagChild (const char *name, const char *attributename, const char *attributevalue) const
 
xmldomnodegetFirstTagChildInSet (const char *const *set) const
 
uint64_t getAttributeCount () const
 
xmldomnodegetAttribute (const char *name) const
 
xmldomnodegetAttribute (uint64_t position) const
 
const char * getAttributeValue (const char *name) const
 
const char * getAttributeValue (uint64_t position) const
 
constnamevaluepairs * getAttributes () const
 
void setAttributeValue (const char *name, const char *value)
 
void setAttributeValue (const char *name, int64_t value)
 
void setAttributeValue (const char *name, uint64_t value)
 
xmldomnodegetNullNode () const
 
bool isNullNode () const
 
void setType (xmldomnodetype type)
 
void setName (const char *name)
 
void setValue (const char *value)
 
void setParent (xmldomnode *parent)
 
void setPreviousSibling (xmldomnode *previous)
 
void setNextSibling (xmldomnode *next)
 
bool insertChild (xmldomnode *child, uint64_t position)
 
bool appendChild (xmldomnode *child)
 
xmldomnodeinsertTag (const char *tag, uint64_t position)
 
xmldomnodeappendTag (const char *tag)
 
bool moveChild (xmldomnode *child, xmldomnode *parent, uint64_t position)
 
bool deleteChild (uint64_t position)
 
bool deleteChild (xmldomnode *child)
 
bool deleteChildren ()
 
bool insertText (const char *value, uint64_t position)
 
bool appendText (const char *value)
 
bool insertAttribute (xmldomnode *attribute, uint64_t position)
 
bool appendAttribute (xmldomnode *attribute)
 
bool insertAttribute (const char *name, const char *value, uint64_t position)
 
bool appendAttribute (const char *name, const char *value)
 
bool deleteAttribute (uint64_t position)
 
bool deleteAttribute (const char *name)
 
bool deleteAttribute (xmldomnode *attribute)
 
stringbufferxml () const
 
void print (stringbuffer *strb) const
 
void print (filedescriptor *fd) const
 
stringbuffergetPath () const
 
xmldomnodegetChildByPath (const char *path) const
 
xmldomnodegetAttributeByPath (const char *path, uint64_t position) const
 
xmldomnodegetAttributeByPath (const char *path, const char *name) const
 
const char * getAttributeValueByPath (const char *path, uint64_t position) const
 
const char * getAttributeValueByPath (const char *path, const char *name) const
 
void setData (void *data)
 
void * getData ()
 

Static Public Member Functions

static xmldomnodecreateNullNode (xmldom *dom)
 

Detailed Description

The xmldomnode class provides a generic container for DOM tree elements. One can navigate the nodes of the tree, modify the tree and read or modify the data that the nodes contain by calling methods in this class.

A DOM tree node can be one of the following: the document root a tag a tag attribute a segment of text a comment a segment of CDATA

Each node may contain the following data, though for some node types, the data container is unused: type name value parent node next sibling previous sibling a list of attribute nodes a list of child nodes

Here is a breakdown by node type:

    For the document root:
            type - ROOT_XMLDOMNODETYPE
            name - "document"
            value - unused
            parent node - unused
            next sibling - unused
            previous sibling - unused
            a list of attribute nodes - unused
            a list of child nodes - the xml version tag, the doctype tag
                                    and the top-level enclosing tag

    For a tag:
            type - TAG_XMLDOMNODETYPE
            name - the tag name
            value - unused
            parent node - the parent tag or document root
            next sibling - can be another tag, a segment of text,
                                     a comment or a segment of cdata
            previous sibling - can be another tag, a segment of text,
                                     a comment or a segment of cdata
            a list of attribute nodes - a list of attribute nodes
            a list of child nodes - a list of tags, text segments, comments
                                    and/or cdata segments

    For a tag attribute:
            type - ATTRIBUTE_XMLDOMNODETYPE
            name - the attribute name
            value - the attribute value
                (note that for tags with standalone
                attributes, the name and value are the same)
            parent node - the tag containing the attributes
            next sibling - the next attribute
            previous sibling - the previous attribute
            a list of attribute nodes - unused
            a list of child nodes - unused

    For a segment of text:
            type - TEXT_XMLDOMNODETYPE
            name - "text"
            value - the text itself
            parent node - the tag containing the text
            next sibling - can be a tag, a comment or a segment of cdata
            previous sibling - can be a tag, a comment or a segment of cdata
            a list of attribute nodes - unused
            a list of child nodes - unused

    For a comment:
            type - COMMENT_XMLDOMNODETYPE
            name - "comment"
            value - the comment itself
            parent node - the tag containing the comment
            next sibling - can be a tag, a segment of text, another
                            comment or a segment of cdata
            previous sibling - can be a tag, a segment of text, another
                            comment or a segment of cdata
            a list of attribute nodes - unused
            a list of child nodes - unused

    For a segment of cdata:
            type - CDATA_XMLDOMNODETYPE
            name - "cdata"
            value - the cdata itself
            parent node - the tag containing the cdata
            next sibling - can be a tag, a segment of text, a comment
                            or another segment of cdata
            previous sibling - can be a tag, a segment of text, a comment
                            or another segment of cdata
            a list of attribute nodes - unused
            a list of child nodes - unused  

Constructor & Destructor Documentation

xmldomnode::xmldomnode ( xmldom dom,
xmldomnode nullnode 
)

Creates a new node and intializes its member variables to NULL.

Your application should pass in a special "nullnode" which may be created by the static method createNullNode() below.

This will keep command chaining like this:

mynode->getChild("node1")-> getChild("node2")->getName("node3");

from causing the program to crash trying to dereference a NULL pointer if, for example, "node2" doesn't exist.

xmldomnode::xmldomnode ( xmldom dom,
xmldomnode nullnode,
xmldomnodetype  type,
const char *  name,
const char *  value 
)

Creates a new node (see xmldomnode(xmldom *, xmldomnode *) and intializes its member variables to the values passed in.

xmldomnode::~xmldomnode ( )

Deletes the node, all attribute nodes and optionally all child nodes, recursively.

Member Function Documentation

bool xmldomnode::appendAttribute ( xmldomnode attribute)

Appends "attribute" to the list of attributes.

bool xmldomnode::appendAttribute ( const char *  name,
const char *  value 
)

Creates an attribute node with "name" and "value" and appends it to the list of attributes.

bool xmldomnode::appendChild ( xmldomnode child)

Appends "child" to the list of child nodes.

xmldomnode* xmldomnode::appendTag ( const char *  tag)

Appends a new node of type TAG_XMLDOMNODETYPE to the list of child nodes.

Returns the new node on success or the null node on failure.

bool xmldomnode::appendText ( const char *  value)

Appends a child node of type TEXT_XMLDOMNODE with value "value" to the list of child nodes.

void xmldomnode::cascadeOnDelete ( )

Instructs the destructor to recursively delete all child nodes. This is the default behavior.

static xmldomnode* xmldomnode::createNullNode ( xmldom dom)
static

Creates a special "null node" whose parent, next sibling and previous siblings point back to itself. This special node should be passed in when creating new xmldomnodes.

This method allocates xmldomnode internally and passes a pointer back. The calling program must ultimately deallocate the node.

bool xmldomnode::deleteAttribute ( uint64_t  position)

Deletes the attribute at "position". The position of the next attribute (and all successive attributes) is decremented.

bool xmldomnode::deleteAttribute ( const char *  name)

Searches the list of attribute nodes for an attribute named "name" and deletes it. The position of the next attribute (and all successive attributes) is decremented.

bool xmldomnode::deleteAttribute ( xmldomnode attribute)

Searches the list of attribute nodes for "attribute" and deletes it. The position of the next attribute (and all successive attributes) is decremented.

bool xmldomnode::deleteChild ( uint64_t  position)

Deletes the child node at "position". The position of the next sibling (and all successive siblings) is decremented.

bool xmldomnode::deleteChild ( xmldomnode child)

Deletes child node "child". The position of the next sibling (and all successive siblings) is decremented.

bool xmldomnode::deleteChildren ( )

Deletes all child nodes.

void xmldomnode::dontCascadeOnDelete ( )

Instructs the destructor not to recursively delete all child nodes. The default behavior is to delete all child nodes.

xmldomnode* xmldomnode::getAttribute ( const char *  name) const

Returns the attribute named "name" or the nullnode if not found.

xmldomnode* xmldomnode::getAttribute ( uint64_t  position) const

Returns the attribute node at index "position" or the nullnode if not found.

xmldomnode* xmldomnode::getAttributeByPath ( const char *  path,
uint64_t  position 
) const

Returns the attribute node at index "position" of the child element with "path" of the form:

/element[index]/element[index]/...

Returns the null node if the specified element was not found.

xmldomnode* xmldomnode::getAttributeByPath ( const char *  path,
const char *  name 
) const

Returns the attribute node named "name" of the child element with "path" of the form:

/element[index]/element[index]/...

Returns the null node if the specified element was not found.

uint64_t xmldomnode::getAttributeCount ( ) const

Returns the number of attributes.

constnamevaluepairs* xmldomnode::getAttributes ( ) const

Returns the attribute names and values in a constnamevaluepairs dictionary. The instance of constnamevaluepairs is allocated internally and must be deleted by the calling program. Returns NULL if the node is a nullNode and an empty dictionary if the node has no attributes.

const char* xmldomnode::getAttributeValue ( const char *  name) const

Returns the value of the attribute named "name" or the nullnode if not found.

const char* xmldomnode::getAttributeValue ( uint64_t  position) const

Returns the value of the attribute node at index "position" or the nullnode if not found.

const char* xmldomnode::getAttributeValueByPath ( const char *  path,
uint64_t  position 
) const

Returns the value of the attribute at index "position" of the child element with "path" of the form:

/element[index]/element[index]/...

Returns the null node if the specified element was not found.

const char* xmldomnode::getAttributeValueByPath ( const char *  path,
const char *  name 
) const

Returns the value of the attribute named "name" of the child element with "path" of the form:

/element[index]/element[index]/...

Returns the null node if the specified element was not found.

xmldomnode* xmldomnode::getChild ( const char *  name) const

Returns the child node named "name" or the nullnode if not found.

xmldomnode* xmldomnode::getChild ( uint64_t  position) const

Returns the child node at index "position" or the nullnode if not found.

xmldomnode* xmldomnode::getChild ( const char *  name,
const char *  attributename,
const char *  attributevalue 
) const

Returns the first child node named "name" with an attribute named "attributename" with value "attributevalue". If "name" is null, then the name of the child node is not checked, and the first child node with any name (with matching attribute name/value) will be returned. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getChildByPath ( const char *  path) const

Returns the child element with "path" of the form:

/element[index]/element[index]/...

Returns the null node if the specified element was not found.

uint64_t xmldomnode::getChildCount ( ) const

Returns the number of immediate child nodes.

void* xmldomnode::getData ( )

Allows an app to get the arbitrary data associated with the node using setData().

xmldomnode* xmldomnode::getFirstTagChild ( ) const

Returns the first child node whose type is TAG_XMLDOMNODE. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getFirstTagChild ( const char *  name) const

Returns the first child node named "name" whose type is TAG_XMLDOMNODE. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getFirstTagChild ( const char *  name,
const char *  attributename,
const char *  attributevalue 
) const

Returns the first child node named "name" with an attribute named "attributename" with value "attributevalue" whose type is TAG_XMLDOMNODE. If "name" is null, then the name of the child node is not checked, and the first child node with any name (with matching attribute name/value) will be returned. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getFirstTagChildInSet ( const char *const *  set) const

Returns the first child node whose type is TAG_XMLDOMNODE and whose name matches one of the members of the NULL-terminated array "set". If no match is found, nullnode is returned.

const char* xmldomnode::getName ( ) const

Returns the node name.

xmldomnode* xmldomnode::getNextSibling ( ) const

Returns a pointer to the next sibling node or the nullnode if none exists.

xmldomnode* xmldomnode::getNextTagSibling ( ) const

Returns a pointer to the next sibling node whose type is TAG_XMLDOMNODE. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getNextTagSibling ( const char *  name) const

Returns the next sibling node named "name" whose type is TAG_XMLDOMNODE or the nullnode if not found.

xmldomnode* xmldomnode::getNextTagSibling ( const char *  name,
const char *  attributename,
const char *  attributevalue 
) const

Returns the next sibling node named "name" with an attribute named "attributename" with value "attributevalue" whose type is TAG_XMLDOMNODE. If "name" is null, then the name of the child node is not checked, and the first child node with any name (with matching attribute name/value) will be returned. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getNextTagSiblingInSet ( const char *const *  set) const

Returns the next sibling node whose type is TAG_XMLDOMNODE and whose name matches one of the members of the NULL-terminated array "set". If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getNullNode ( ) const

Returns the nullnode used by this node.

xmldomnode* xmldomnode::getParent ( ) const

Returns a pointer to the parent node or the nullnode if none exists.

stringbuffer* xmldomnode::getPath ( ) const

If the xmldomnode is an element, returns the "path" of the xmldomnode. The path will have the following form:

/element[index]/element[index]/...

The return value is allocated inside the method and must be deallocated by the calling program.

uint64_t xmldomnode::getPosition ( ) const

Returns the position of the node, relative to its siblings.

xmldomnode* xmldomnode::getPreviousSibling ( ) const

Returns a pointer to the previous sibling node or the nullnode if none exists.

xmldomnode* xmldomnode::getPreviousTagSibling ( ) const

Returns a pointer to the previous sibling node whose type is TAG_XMLDOMNODE. If no match is found, nullnode is returned.

xmldomnode* xmldomnode::getPreviousTagSibling ( const char *  name) const

Returns the previous sibling node named "name" whose type is TAG_XMLDOMNODE or the nullnode if not found.

xmldomnode* xmldomnode::getPreviousTagSibling ( const char *  name,
const char *  attributename,
const char *  attributevalue 
) const

Returns the previous sibling node named "name" with an attribute named "attributename" with value "attributevalue" whose type is TAG_XMLDOMNODE. If "name" is null, then the name of the child node is not checked, and the first child node with any name (with matching attribute name/value) will be returned. If no match is found, nullnode is returned.

xmldom* xmldomnode::getTree ( ) const

Returns a pointer to the tree that this node is attached to or NULL if it isn't attached to any tree.

xmldomnodetype xmldomnode::getType ( ) const

Returns the node type.

const char* xmldomnode::getValue ( ) const

Returns the node value.

bool xmldomnode::insertAttribute ( xmldomnode attribute,
uint64_t  position 
)

Inserts "attribute" into the list of attributes at "position". The position of the next attribute (and all successive attributes) is incremented.

bool xmldomnode::insertAttribute ( const char *  name,
const char *  value,
uint64_t  position 
)

Creates an attribute node with "name" and "value" and inserts it into the list of attributes at "position". The position of the next attribute (and all successive attributes) is incremented.

bool xmldomnode::insertChild ( xmldomnode child,
uint64_t  position 
)

Inserts "child" into the list of child nodes at "position". The position of the next sibling (and all successive siblings) is incremented.

xmldomnode* xmldomnode::insertTag ( const char *  tag,
uint64_t  position 
)

Inserts a new node of type TAG_XMLDOMNODETYPE with name "tag" into the list of child nodes at "position". The position of the next sibling (and all successive siblings) is incremented.

Returns the new node on success or the null node on failure.

bool xmldomnode::insertText ( const char *  value,
uint64_t  position 
)

Inserts a child node of type TEXT_XMLDOMNODE with value "value" into the list of child nodes at "position". The position of the next sibling (and all successive siblings) is incremented.

bool xmldomnode::isNullNode ( ) const

Returns true if this node is the special nullnode and false otherwise.

bool xmldomnode::moveChild ( xmldomnode child,
xmldomnode parent,
uint64_t  position 
)

Moves "child" from its current position into the list of child nodes for "parent" at "position".

void xmldomnode::print ( stringbuffer strb) const

Prints a text representation of the tree starting at this node into "strb".

void xmldomnode::print ( filedescriptor fd) const

Prints a text representation of the tree starting at this node to filedescriptor "fd".

void xmldomnode::setAttributeValue ( const char *  name,
const char *  value 
)

Sets the value of the attribute named "name" to "value". Creates attribute "name" if it didn't previously exist.

void xmldomnode::setAttributeValue ( const char *  name,
int64_t  value 
)

Sets the value of the attribute named "name" to "value". Creates attribute "name" if it didn't previously exist.

void xmldomnode::setAttributeValue ( const char *  name,
uint64_t  value 
)

Sets the value of the attribute named "name" to "value". Creates attribute "name" if it didn't previously exist.

void xmldomnode::setData ( void *  data)

Allows an app to associate arbitrary data with the node.

void xmldomnode::setName ( const char *  name)

Sets the node name to "name".

void xmldomnode::setNextSibling ( xmldomnode next)

Sets the next sibling of the node to "next".

void xmldomnode::setParent ( xmldomnode parent)

Sets the parent of the node to "parent".

void xmldomnode::setPreviousSibling ( xmldomnode previous)

Sets the previous sibling of the node to "previous".

void xmldomnode::setType ( xmldomnodetype  type)

Sets the node type to "type".

void xmldomnode::setValue ( const char *  value)

Sets the node value to "value".

stringbuffer* xmldomnode::xml ( ) const

Allocates a stringbuffer, writes a text representation of the tree starting at this node to it and returns the stringbuffer; The calling program must deallocate the stringbuffer.