C++ Language Binding for DOM Level 2

[Back to Readme] [Go to C++ Language Binding for DOM Level 3]

This document contains the complete Apache Recommended C++ Language binding for the Document Object Model Level 2.0 Core, and for the Document Object Model Level 2.0 Traversal and Range.  Both are W3C Recommendation of November 13, 2000.

The definitions are divided into Core, Traversal, and Range. The headers are also available in Xerces-C++ distribution.

Note:

  1. Constructor and Destructors are implementation specific
  2. String is represented by "XMLCh*" which is a pointer to unsigned 16 bit type holding utf-16 values, null terminated.
  3. XMLSize_t is an implementation-dependent unsigned integral type
  4. C++ Memory Management:
    1. A member method "release()" is added for releasing any "orphaned" resources that were created through createXXXX factory method.
    2. Memory for any returned object e.g.
      • DOMNodeList* getChildNodes()
      • DOMNodeList* getElementsByTagName()
      • NamedNodeMap* getEntities()
      • ... etc.
      • are owned by implementation

Change History

Date Description
Xerces-C++ 2.0: July 23, 2002 Created
Xerces-C++ 2.1: August 26, 2002 Modified
- add const modifier to DOMNodeList::getLength
- add const modifier to DOMNodeList::item
Xerces-C++ 2.2: February 7, 2003 Modified
- add const modifier to DOMImplementation::hasFeature
- fix typo: "Mode:" -> "Model"


A: Document Object Model: Core

DOMException.hpp:

class DOMException
{
public:
enum ExceptionCode {
INDEX_SIZE_ERR = 1,
DOMSTRING_SIZE_ERR = 2,
HIERARCHY_REQUEST_ERR = 3,
WRONG_DOCUMENT_ERR = 4,
INVALID_CHARACTER_ERR = 5,
NO_DATA_ALLOWED_ERR = 6,
NO_MODIFICATION_ALLOWED_ERR = 7,
NOT_FOUND_ERR = 8,
NOT_SUPPORTED_ERR = 9,
INUSE_ATTRIBUTE_ERR = 10,
INVALID_STATE_ERR = 11,
SYNTAX_ERR = 12,
INVALID_MODIFICATION_ERR = 13,
NAMESPACE_ERR = 14,
INVALID_ACCESS_ERR = 15
};
ExceptionCode code;
const XMLCh* msg;
};

DOMImplementation.hpp:

class DOMImplementation
{
public:
virtual bool hasFeature(const XMLCh* feature,
           const XMLCh* version) const = 0;
virtual DOMDocumentType* createDocumentType(const XMLCh* qualifiedName,
                   const XMLCh* publicId,
                   const XMLCh* systemId) = 0;
virtual DOMDocument* createDocument(const XMLCh* namespaceURI,
               const XMLCh* qualifiedName,
               DOMDocumentType* doctype) = 0;
};

DOMDocumentFragment.hpp:

class DOMDocumentFragment : public DOMNode
{
};

DOMDocument.hpp:

class DOMDocument : public DOMNode
{
public:
virtual DOMElement* createElement(const XMLCh* tagName) = 0;
virtual DOMDocumentFragment* createDocumentFragment() = 0;
virtual DOMText* createTextNode(const XMLCh* data) = 0;
virtual DOMComment* createComment(const XMLCh* data) = 0;
virtual DOMCDATASection* createCDATASection(const XMLCh* data) = 0;
virtual DOMProcessingInstruction* createProcessingInstruction(const XMLCh* target,
                            const XMLCh* data) = 0;
virtual DOMAttr* createAttribute(const XMLCh* name) = 0;
virtual DOMEntityReference* createEntityReference(const XMLCh* name) = 0;
virtual DOMDocumentType* getDoctype() const = 0;
virtual DOMImplementation* getImplementation() const = 0;
virtual DOMElement* getDocumentElement() const = 0;
virtual DOMNodeList* getElementsByTagName(const XMLCh* tagname) const = 0;
virtual DOMNode* importNode(DOMNode* importedNode, bool deep) = 0;
virtual DOMElement* createElementNS(const XMLCh* namespaceURI,
                const XMLCh* qualifiedName) = 0;
virtual DOMAttr* createAttributeNS(const XMLCh* namespaceURI,
                  const XMLCh* qualifiedName) = 0;
virtual DOMNodeList* getElementsByTagNameNS(const XMLCh* namespaceURI,
                       const XMLCh* localName) const = 0;
virtual DOMElement* getElementById(const XMLCh* elementId) const = 0;
};

DOMNode.hpp:

class DOMNode
{
public:
enum NodeType {
ELEMENT_NODE = 1,
ATTRIBUTE_NODE = 2,
TEXT_NODE = 3,
CDATA_SECTION_NODE = 4,
ENTITY_REFERENCE_NODE = 5,
ENTITY_NODE = 6,
PROCESSING_INSTRUCTION_NODE = 7,
COMMENT_NODE = 8,
DOCUMENT_NODE = 9,
DOCUMENT_TYPE_NODE = 10,
DOCUMENT_FRAGMENT_NODE = 11,
NOTATION_NODE = 12,
};
virtual const XMLCh* getNodeName() const = 0;
virtual const XMLCh* getNodeValue() const = 0;
virtual short getNodeType() const = 0;
virtual DOMNode* getParentNode() const = 0;
virtual DOMNodeList* getChildNodes() const = 0;
virtual DOMNode* getFirstChild() const = 0;
virtual DOMNode* getLastChild() const = 0;
virtual DOMNode* getPreviousSibling() const = 0;
virtual DOMNode* getNextSibling() const = 0;
virtual DOMNamedNodeMap* getAttributes() const = 0;
virtual DOMDocument* getOwnerDocument() const = 0;
virtual DOMNode* cloneNode(bool deep) const = 0;
virtual DOMNode* insertBefore(DOMNode* newChild, DOMNode* refChild) = 0;
virtual DOMNode* replaceChild(DOMNode* newChild, DOMNode* oldChild) = 0;
virtual DOMNode* removeChild(DOMNode* oldChild) = 0;
virtual DOMNode* appendChild(DOMNode* newChild) = 0;
virtual bool hasChildNodes() const = 0;
virtual void setNodeValue(const XMLCh *nodeValue) = 0;
virtual void normalize() = 0;
virtual bool isSupported(const XMLCh* feature, const XMLCh* version) const = 0;
virtual const XMLCh* getNamespaceURI() const = 0;
virtual const XMLCh* getPrefix() const = 0;
virtual const XMLCh* getLocalName() const = 0;
virtual void setPrefix(const XMLCh* prefix) = 0;
virtual bool hasAttributes() const = 0;

  //
  // Called to indicate that this Node (and its associated children) is no longer in use
  //  and that the implementation may relinquish any resources associated with it and
  //  its associated children.
  //
  // If this is a document, any nodes it owns (created by DOMDocument::createXXXX())
  //  are also released.
  //
  // Access to a released object will lead to unexpected result.
  //
  // @exception DOMException
  //   INVALID_ACCESS_ERR: Raised if this Node has a parent and thus should not be released yet.
  //
  virtual void                         release() = 0;
};

DOMNodeList.hpp:

class DOMNodeList
{
public:
virtual DOMNode* item(XMLSize_t index) const = 0;
virtual XMLSize_t getLength() const = 0;
};

DOMNamedNodeMap.hpp:

class DOMNamedNodeMap
{
public:
virtual DOMNode* setNamedItem(DOMNode* arg) = 0;
virtual DOMNode* item(XMLSize_t index) const = 0;
virtual DOMNode* getNamedItem(const XMLCh* name) const = 0;
virtual XMLSize_t getLength() const = 0;
virtual DOMNode* removeNamedItem(const XMLCh* name) = 0;
virtual DOMNode* getNamedItemNS(const XMLCh* namespaceURI, const XMLCh* localName) const = 0;
virtual DOMNode* setNamedItemNS(DOMNode* arg) = 0;
virtual DOMNode* removeNamedItemNS(const XMLCh* namespaceURI, const XMLCh* localName) = 0;
};

DOMCharacterData.hpp:

class DOMCharacterData : public DOMNode
{
public:
virtual const XMLCh* getData() const = 0;
virtual XMLSize_t getLength() const = 0;
virtual const XMLCh* substringData(XMLSize_t offset, XMLSize_t count) const = 0;
virtual void appendData(const XMLCh* arg) = 0;
virtual void insertData(XMLSize_t offset, const XMLCh* arg) = 0;
virtual void deleteData(XMLSize_t offset, XMLSize_t count) = 0;
virtual void replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh* arg) = 0;
virtual void setData(const XMLCh* data) = 0;
};

DOMAttr.hpp:

class DOMAttr : public DOMNode
{
public:
virtual const XMLCh* getName() const = 0;
virtual bool getSpecified() const = 0;
virtual const XMLCh* getValue() const = 0;
virtual void setValue(const XMLCh* value) = 0;
virtual DOMElement* getOwnerElement() const = 0;
};

DOMElement.hpp:

class DOMElement : public DOMNode
{
public:
virtual const XMLCh* getTagName() const = 0;
virtual const XMLCh* getAttribute(const XMLCh* name) const = 0;
virtual DOMAttr* getAttributeNode(const XMLCh* name) const = 0;
virtual DOMNodeList* getElementsByTagName(const XMLCh* name) const = 0;
virtual void setAttribute(const XMLCh* name, const XMLCh* value) = 0;
virtual DOMAttr* setAttributeNode(DOMAttr *newAttr) = 0;
virtual DOMAttr* removeAttributeNode(DOMAttr* oldAttr) = 0;
virtual void removeAttribute(const XMLCh* name) = 0;
virtual const XMLCh* getAttributeNS(const XMLCh* namespaceURI,
               const XMLCh* localName) const = 0;
virtual void setAttributeNS(const XMLCh* namespaceURI,
               const XMLCh* qualifiedName,
               const XMLCh* value) = 0;
virtual void removeAttributeNS(const XMLCh* namespaceURI,
                  const XMLCh* localName) = 0;
virtual DOMAttr* getAttributeNodeNS(const XMLCh* namespaceURI,
                   const XMLCh* localName) const = 0;
virtual DOMAttr* setAttributeNodeNS(DOMAttr* newAttr) = 0;
virtual DOMNodeList* getElementsByTagNameNS(const XMLCh* namespaceURI,
                       const XMLCh* localName) const = 0;
virtual bool hasAttribute(const XMLCh* name) const = 0;
virtual bool hasAttributeNS(const XMLCh* namespaceURI,
               const XMLCh* localName) const = 0;
};

DOMText.hpp:

class DOMText : DOMCharacterData
{
public:
virtual DOMText* splitText(XMLSize_t offset) = 0;
};

DOMComment.hpp:

class DOMComment : DOMCharacterData
{
};

DOMCDATASection.hpp:

class DOMCDATASection : DOMText
{
};

DOMDocumentType.hpp:

class DOMDocumentType : DOMNode
{
public:
virtual const XMLCh* getName() const = 0;
virtual DOMNamedNodeMap* getEntities() const = 0;
virtual DOMNamedNodeMap* getNotations() const = 0;
virtual const XMLCh* getPublicId() const = 0;
virtual const XMLCh* getSystemId() const = 0;
virtual const XMLCh* getInternalSubset() const = 0;
};

DOMNotation.hpp:

class DOMNotation : DOMNode
{
public:
virtual const XMLCh* getPublicId() const = 0;
virtual const XMLCh* getSystemId() const = 0;
};

DOMEntity.hpp:

class DOMEntity : DOMNode
{
public:
virtual const XMLCh* getPublicId() const = 0;
virtual const XMLCh* getSystemId() const = 0;
virtual const XMLCh* getNotationName() const = 0;
};

DOMEntityReference.hpp:

class DOMEntityReference : DOMNode
{
};

DOMProcessingInstruction.hpp:

class DOMProcessingInstruction : DOMNode
{
public:
virtual const XMLCh* getTarget() const = 0;
virtual const XMLCh* getData() const = 0;
virtual void* setData(const XMLCh* data) = 0;
};

B: Document Object Model: Traversal

DOMNodeIterator.hpp:

class DOMNodeIterator
{
public:
virtual DOMNode* getRoot() const = 0;
virtual unsigned long getWhatToShow() const = 0;
virtual DOMNodeFilter* getFilter() const = 0;
virtual bool getExpandEntityReferences() const = 0;
virtual DOMNode* nextNode() = 0;
virtual DOMNode* previousNode() = 0;
virtual void detach() = 0;

  //
  // Called to indicate that this NodeIterator is no longer in use
  //   and that the implementation may relinquish any resources associated with it.
  //   (release() will call detach() where appropriate)
  //
  // Access to a released object will lead to unexpected result.
  //
  virtual void            release() = 0;
};
 

DOMNodeFilter.hpp:

class DOMNodeFilter
{
public:
enum FilterAction {
FILTER_ACCEPT = 1,
FILTER_REJECT = 2,
FILTER_SKIP = 3,
};
enum ShowType {
SHOW_ALL = 0x0000FFFF,
SHOW_ELEMENT = 0x00000001,
SHOW_ATTRIBUTE = 0x00000002,
SHOW_TEXT = 0x00000004,
SHOW_CDATA_SECTION = 0x00000008,
SHOW_ENTITY_REFERENCE = 0x00000010,
SHOW_ENTITY = 0x00000020,
SHOW_PROCESSING_INSTRUCTION = 0x00000040,
SHOW_COMMENT = 0x00000080,
SHOW_DOCUMENT = 0x00000100,
SHOW_DOCUMENT_TYPE = 0x00000200,
SHOW_DOCUMENT_FRAGMENT = 0x00000400,
SHOW_NOTATION = 0x00000800,
};
virtual short acceptNode (const DOMNode* node) const = 0;
};

DOMTreeWalker.hpp:

class DOMTreeWalker
{
public:
virtual DOMNode* getRoot() const = 0;
virtual unsigned long getWhatToShow()const = 0;
virtual DOMNodeFilter* getFilter()const = 0;
virtual bool getExpandEntityReferences()const = 0;
virtual DOMNode* getCurrentNode()const = 0;
virtual void setCurrentNode(DOMNode* currentNode)= 0;
virtual DOMNode* parentNode()= 0;
virtual DOMNode* firstChild()= 0;
virtual DOMNode* lastChild()= 0;
virtual DOMNode* previousSibling()= 0;
virtual DOMNode* nextSibling()= 0;
virtual DOMNode* previousNode()= 0;
virtual DOMNode* nextNode()= 0;

  //
  // Called to indicate that this TreeWalker is no longer in use
  //   and that the implementation may relinquish any resources associated with it.
  //
  // Access to a released object will lead to unexpected result.
  //
  virtual void           release() = 0;
};

DOMDocumentTraversal.hpp:

// This interface can be obtained from the object implementing the
// Document interface using binding-specific casting methods.
class DOMDocumentTraversal
{
public:
virtual DOMNodeIterator* createNodeIterator(DOMNode* root,
                   unsigned long whatToShow,
                   DOMNodeFilter* filter,
                   bool entityReferenceExpansion) = 0;
virtual DOMTreeWalker* createTreeWalker(DOMNode* root,
                 unsigned long whatToShow,
                 DOMNodeFilter* filter,
                 bool entityReferenceExpansion) = 0;
};

C: Document Object Model: Range

DOMRangeException.hpp:

class DOMRangeException : DOMException
{
public:
enum DOMRangeExceptionCode {
BAD_BOUNDARYPOINTS_ERR = 1,
INVALID_NODE_TYPE_ERR = 2,
};
DOMRangeExceptionCode code;
};

DOMRange.hpp:

class DOMRange
{
public:
enum CompareHow {
START_TO_START = 1,
START_TO_END = 2,
END_TO_END = 3,
END_TO_START = 4,
};
virtual DOMNode* getStartContainer() const = 0;
virtual XMLSize_t getStartOffset() const = 0;
virtual DOMNode* getEndContainer() const = 0;
virtual XMLSize_t getEndOffset() const = 0;
virtual bool getCollapsed() const = 0;
virtual const DOMNode* getCommonAncestorContainer() const = 0;
virtual void setStart(const DOMNode* parent, XMLSize_t offset) = 0;
virtual void setEnd(const DOMNode* parent, XMLSize_t offset) = 0;
virtual void setStartBefore(const DOMNode* refNode) = 0;
virtual void setStartAfter(const DOMNode* refNode) = 0;
virtual void setEndBefore(const DOMNode* refNode) = 0;
virtual void setEndAfter(const DOMNode* refNode) = 0;
virtual void collapse(bool toStart) = 0;
virtual void selectNode(const DOMNode* node) = 0;
virtual void selectNodeContents(const DOMNode* node) = 0;
virtual short compareBoundaryPoints(CompareHow how, const DOMRange* range) const = 0;
virtual void deleteContents() = 0;
virtual DOMDocumentFragment* extractContents() = 0;
virtual DOMDocumentFragment* cloneContents() const = 0;
virtual void insertNode(DOMNode* node) = 0;
virtual void surroundContents(DOMNode* node) = 0;
virtual DOMRange* cloneRange() const = 0;
virtual const XMLCh* toString() const = 0;
virtual void detach() = 0;

  //
  // Called to indicate that this Range is no longer in use
  //   and that the implementation may relinquish any resources associated with it.
  //   (release() will call detach() where appropriate)
  //
  // Access to a released object will lead to unexpected result.
  //
  virtual void              release() = 0;
};

DOMDocumentRange.hpp:

// This interface can be obtained from the object implementing the
// Document interface using binding-specific casting methods.
class DOMDocumentRange
{
public:
virtual DOMRange* createRange() = 0;
};

Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.