Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::xom::Node Class Referenceabstract

#include <elm/xom/Node.h>

+ Inheritance diagram for elm::xom::Node:

Public Types

enum  kind_t {
  NONE = 0, ELEMENT, DOCUMENT, TEXT,
  COMMENT, ATTRIBUTE, PROCESSING_INSTRUCTION, DOCTYPE,
  NAMESPACE
}
 
typedef enum elm::xom::Node::kind_t kind_t
 

Public Member Functions

virtual ~Node (void)
 
void * getNode (void) const
 
kind_t kind (void) const
 
virtual Nodecopy (void)=0
 
void detach (void)
 
bool equals (const Node *node) const
 
virtual String getBaseURI (void)
 
virtual NodegetChild (int index)=0
 
virtual int getChildCount (void)=0
 
virtual DocumentgetDocument (void)
 
virtual ParentNodegetParent (void)
 
virtual String getValue (void)=0
 
virtual Nodesquery (const String &xpath)
 
virtual Nodesquery (const String &xpath, XPathContext *context)
 
virtual String toXML (void)=0
 
int line (void) const
 

Protected Member Functions

 Node (void *_node)
 
void setNode (void *_node)
 
Nodemake (void *node)
 
Nodeget (void *node)
 
NodeinternCopy (void)
 
NodeinternGetChild (int index)
 
int internGetChildCount (void)
 
String internGetValue (void)
 
String internToXML (void)
 

Static Protected Member Functions

static void freeNode (void *node)
 

Protected Attributes

void * node
 

Detailed Description

The base class of nodes of a XOM XML tree. Refer to http://www.xom.nu/ for more information.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
NONE 
ELEMENT 
DOCUMENT 
TEXT 
COMMENT 
ATTRIBUTE 
PROCESSING_INSTRUCTION 
DOCTYPE 
NAMESPACE 

Constructor & Destructor Documentation

elm::xom::Node::Node ( void *  _node)
protected

References setNode().

elm::xom::Node::~Node ( void  )
virtual

Member Function Documentation

virtual Node* elm::xom::Node::copy ( void  )
pure virtual
void elm::xom::Node::detach ( void  )

Detach the current node from its parent.

References node.

bool elm::xom::Node::equals ( const Node node) const

Test if the current and the passed nodes are equals, that is, they are the same object.

References node.

void elm::xom::Node::freeNode ( void *  _node)
staticprotected

Free a tree of nodes.

References node.

Referenced by elm::xom::ParentNode::appendChild().

Node * elm::xom::Node::get ( void *  xml_node)
protected

Get the XOM object linked with this parser representation node.

Parameters
xml_nodeParser node.
Returns
Matching XOM node.

References make().

Referenced by elm::xom::XSLTransform::toDocument().

String elm::xom::Node::getBaseURI ( void  )
virtual

Returns the base URI of this node as specified by XML Base, or the empty string if this is not known. In most cases, this is the URL against which relative URLs in this node should be resolved.

The base URI of a non-parent node is the base URI of the element containing the node. The base URI of a document node is the URI from which the document was parsed, or which was set by calling setBaseURI on on the document.
The base URI of an element is determined as follows:
  • If the element has an xml:base attribute, then the value of that attribute is converted from an IRI to a URI, absolutized if possible, and returned.
  • Otherwise, if any ancestor element of the element loaded from the same entity has an xml:base attribute, then the value of that attribute from the nearest such ancestor is converted from an IRI to a URI, absolutized if possible, and returned. xml:base attributes from other entities are not considered.
  • Otherwise, if setBaseURI() has been invoked on this element, then the URI most recently passed to that method is absolutized if possible and returned.
  • Otherwise, if the element comes from an externally parsed entity or the document entity, and the original base URI has not been changed by invoking setBaseURI(), then the URI of that entity is returned. , (the element was created by a constructor rather then being parsed from an existing document), the base URI of the nearest ancestor that does have a base URI is returned. If no ancestors have a base URI, then the empty string is returned.
Absolutization takes place as specified by the XML Base specification. However, it is not always possible to absolutize a relative URI, in which case the empty string will be returned.
Returns
the base URI of this node. This string must be fried by the caller.

Reimplemented in elm::xom::Attribute, and elm::xom::Document.

References node.

Node * elm::xom::Node::getChild ( int  index)
pure virtual

Returns the child of this node at the specified position.

Parameters
positionthe index of the child node to return
Returns
the positionth child node of this node

Implemented in elm::xom::Attribute, elm::xom::Comment, elm::xom::ParentNode, and elm::xom::Text.

virtual int elm::xom::Node::getChildCount ( void  )
pure virtual
Document * elm::xom::Node::getDocument ( void  )
virtual

Returns the document that contains this node, or null if this node is not currently part of a document. Each node belongs to no more than one document at a time. If this node is a Document, then it returns this node.

Returns
the document this node is a part of

References node.

Referenced by internToXML().

ParentNode * elm::xom::Node::getParent ( void  )
virtual

Get the parent node.

Returns
Parent node.

References make(), and node.

String elm::xom::Node::getValue ( void  )
pure virtual

Get the node as a string with markup removed.

Returns
Text value of the node. The returned string must be fried by the caller.

Implemented in elm::xom::Element, elm::xom::Attribute, elm::xom::Comment, elm::xom::Document, and elm::xom::Text.

Node* elm::xom::Node::internCopy ( void  )
protected
Node * elm::xom::Node::internGetChild ( int  index)
protected
int elm::xom::Node::internGetChildCount ( void  )
protected

int Node::getChildCount(void); Returns the number of children of this node. This is always non-negative (greater than or equal to zero).

Returns
the number of children of this node

Referenced by elm::xom::Text::getChildCount(), and elm::xom::Comment::getChildCount().

String elm::xom::Node::internGetValue ( void  )
protected
String elm::xom::Node::internToXML ( void  )
protected

String Node::toXML(void); Returns the actual XML form of this node, such as might be copied and pasted from the original document. However, this does not preserve semantically insignificant details such as white space inside tags or the use of empty-element tags vs. start-tag end-tag pairs.

Returns
an XML representation of this node. The returned string must be fried by the caller.

References getDocument(), and node.

Referenced by elm::xom::Text::toXML(), and elm::xom::Comment::toXML().

int elm::xom::Node::line ( void  ) const

Get the line of the node in the source file (if any).

Returns
File line of the node, -1 if no one is found.

References node.

Node * elm::xom::Node::make ( void *  node)
protected
Nodes * elm::xom::Node::query ( const String xpath)
virtual

Returns the nodes selected by the XPath expression in the context of this node in document order as defined by XSLT. This XPath expression must not contain any namespace prefixes.

No variables are bound. No namespace prefixes are bound.
Parameters
xpaththe XPath expression to evaluate
Returns
a list of all matched nodes; possibly empty
Exceptions
XPathExceptionif there's a syntax error in the expression; or the query returns something other than a node-set.
Nodes * elm::xom::Node::query ( const String xpath,
XPathContext *  context 
)
virtual

Returns the nodes selected by the XPath expression in the context of this node in document order as defined in XSLT. All namespace prefixes used in the expression should be bound to namespace URIs by the second argument.

Note that XPath expressions operate on the XPath data model, not the XOM data model. XPath counts all adjacent Text objects as a single text node, and does not consider empty Text objects. For instance, an element that has exactly three text children in XOM, will have exactly one text child in XPath, whose value is the concatenation of all three XOM Text objects.
You can use XPath expressions that use the namespace axis. However, namespace nodes are never returned. If an XPath expression only selects namespace nodes, then this method will return an empty list.
No variables are bound.
The context position is the index of this node among its parents children, counting adjacent text nodes as one. The context size is the number of children this node's parent has, again counting adjacent text nodes as one node. If the parent is a Document, then the DocType (if any) is not counted. If the node has no parent, then the context position is 1, and the context size is 1.
Queries such as / *, //, and / * //p that refer to the root node do work when operating with a context node that is not part of a document. However, the query / (return the root node) throws an XPathException when applied to a node that is not part of the document. Furthermore the top-level node in the tree is treated as the first and only child of the root node, not as the root node itself. For instance, this query stores parent in the result variable, not child:
Element parent = new Element("parent");
Element child = new Element("child");
parent.appendChild(child);
Nodes results = child.query("/ *");
Node result = result.get(0);
Parameters
xpaththe XPath expression to evaluate
namespacesa collection of namespace prefix bindings used in the XPath expression
Returns
a list of all matched nodes; possibly empty
Exceptions
XPathExceptionif there's a syntax error in the expression, the query returns something other than a node-set
void elm::xom::Node::setNode ( void *  _node)
protected

Set the actual libxml node.

Parameters
_nodeNode to set.

Referenced by elm::xom::Element::addAttribute(), elm::xom::ParentNode::appendChild(), and Node().

virtual String elm::xom::Node::toXML ( void  )
pure virtual

Member Data Documentation


The documentation for this class was generated from the following files: