Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Node Class Referenceabstract

#include <elm/xom/Node.h>

+ Inheritance diagram for 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)
 
voidgetNode (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

voidnode
 

Detailed Description

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

Member Typedef Documentation

◆ kind_t

Member Enumeration Documentation

◆ kind_t

enum kind_t
Enumerator
NONE 
ELEMENT 
DOCUMENT 
TEXT 
COMMENT 
ATTRIBUTE 
PROCESSING_INSTRUCTION 
DOCTYPE 
NAMESPACE 

Constructor & Destructor Documentation

◆ Node()

Node ( void _node)
protected

References Node::setNode().

◆ ~Node()

~Node ( void  )
virtual

Member Function Documentation

◆ copy()

virtual Node* copy ( void  )
pure virtual

◆ detach()

void detach ( void  )

Detach the current node from its parent.

References Node::node.

◆ equals()

bool equals ( const Node node) const

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

References Node::node.

◆ freeNode()

void freeNode ( void _node)
staticprotected

Free a tree of nodes.

References Node::node.

Referenced by ParentNode::appendChild().

◆ get()

Node * get ( void xml_node)
inlineprotected

Get the XOM object linked with this parser representation node.

Parameters
xml_nodeParser node.
Returns
Matching XOM node.

References Node::make().

Referenced by Element::getAttribute(), Node::getDocument(), and Document::getRootElement().

◆ getBaseURI()

String 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. @liOtherwise, (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 Attribute, and Document.

References Node::node.

◆ getChild()

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 UnsupportedNode, Attribute, Comment, ParentNode, and Text.

◆ getChildCount()

virtual int getChildCount ( void  )
pure virtual

Implemented in UnsupportedNode, Attribute, Comment, ParentNode, and Text.

◆ getDocument()

Document * 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::get(), and Node::node.

Referenced by Node::internToXML(), and XOMUnserializer::XOMUnserializer().

◆ getNode()

◆ getParent()

ParentNode * getParent ( void  )
virtual

Get the parent node.

Returns
Parent node.

References Node::make(), and Node::node.

◆ getValue()

String 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 UnsupportedNode, Element, Attribute, Comment, Document, and Text.

◆ internCopy()

Node* internCopy ( void  )
protected

◆ internGetChild()

Node * internGetChild ( int  index)
protected

◆ internGetChildCount()

int 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 Text::getChildCount(), Comment::getChildCount(), and UnsupportedNode::getChildCount().

◆ internGetValue()

String internGetValue ( void  )
protected

◆ internToXML()

String 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 Node::getDocument(), and Node::node.

Referenced by Text::toXML(), Comment::toXML(), and UnsupportedNode::toXML().

◆ kind()

◆ line()

int 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.

◆ make()

Node * make ( void node)
protected

Build the XOM tree from the parser nodes.

Parameters
nodeParser node.
Returns
Matching XOM node if any.

References NodeFactory::makeComment(), NodeFactory::makeElement(), NodeFactory::makeText(), and Node::node.

Referenced by Node::get(), ParentNode::getChild(), Element::getChildElements(), Element::getFirstChildElement(), and Node::getParent().

◆ query() [1/2]

Nodes * 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.

◆ query() [2/2]

Nodes * 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

◆ setNode()

void setNode ( void _node)
protected

Set the actual libxml node.

Parameters
_nodeNode to set.

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

◆ toXML()

virtual String toXML ( void  )
pure virtual

Member Data Documentation

◆ node


The documentation for this class was generated from the following files:
elm::xom::Node::Node
Node(void *_node)
Definition: xom_Node.cpp:131