Node Interface | nodeName | nodeValue | nodeType |
---|---|---|---|
DOM_Attr | name of attribute | value of attribute | DOM_ATTRIBUTE_NODE |
DOM_CDATASection | "#cdata-section" |
content of the CDATA Section | DOM_CDATA_SECTION_NODE |
DOM_Comment | "#comment" |
content of the comment | DOM_COMMENT_NODE |
DOM_Document | "#document" |
NULL | DOM_DOCUMENT_NODE |
DOM_DocumentFragment | "#document-fragment" |
NULL | DOM_DOCUMENT_FRAGMENT_NODE |
DOM_DocumentType | document type name | NULL | DOM_DOCUMENT_TYPE_NODE |
DOM_Element | tag name | NULL | DOM_ELEMENT_NODE |
DOM_Entity | entity name | NULL | DOM_ENTITY_NODE |
DOM_EntityReference | name of entity referenced | NULL | DOM_ENTITY_REFERENCE_NODE |
DOM_Notation | notation name | NULL | DOM_NOTATION_NODE |
DOM_ProcessingInstruction | target | content excluding target | DOM_PROCESSING_INSTRUCTION_NODE |
DOM_Text | "#text" |
content of the text node | DOM_TEXT_NODE |
Only the DOM_Element node type has attributes. All other node types have a NULL attributes member. Child nodes are accessable through the childNodes DOM_NodeList member and the firstChild, lastChild, previousSibling, and nextSibling members. Not all element types have child nodes.
In DOMC node inheritance is emulated with simple typedef statements and a union that contains all possible subclass attributes. To access a child interface specific attribute it may be necessary to access it through this union. For example the systemId of a notation node is currently only accessible through the union like:
DOM_String *sysid; ... sysid = node->u.Notation.systemId;Care must be taken when modifing these union members (this is not well defined yet). Attributes accessible through the union that may need to be modified have helper methods to make this less awkward. The DOM_Node_setNodeValue function must be used to set the nodeValue member.
DOM_Node_getNodeValue | get nodeValue attribute |
DOM_Node_setNodeValue | set nodeValue and corresponding value in child interface |
DOM_Document_getDoctype | get the doctype node of the document |
DOM_Document_getDocumentElement | get the documentElement of the document |
DOM_CharacterData_getLength | get the length of a DOM_Text, DOM_Comment, DOM_CDATASection, or DOM_ProcessingInstruction |
The all-important DOM_Node structure follows although some fields are left out in the interest of brevity. It may be necessary to look at this structure in the domc.h header.
struct DOM_Node { DOM_String *nodeName; DOM_String *nodeValue; unsigned short nodeType; DOM_Node *parentNode; DOM_NodeList *childNodes; DOM_Node *firstChild; DOM_Node *lastChild; DOM_Node *previousSibling; DOM_Node *nextSibling; DOM_NamedNodeMap *attributes; DOM_Document *ownerDocument; union { struct { DOM_DocumentType *doctype; DOM_Element *documentElement; DOM_String *version; DOM_String *encoding; int standalone; } Document; struct { DOM_NamedNodeMap *entities; DOM_NamedNodeMap *notations; DOM_String *publicId; DOM_String *systemId; DOM_String *internalSubset; } DocumentType; struct { int specified; DOM_Element *ownerElement; } Attr; struct { int length; } CharacterData; struct { DOM_String *publicId; DOM_String *systemId; } Notation; struct { DOM_String *publicId; DOM_String *systemId; DOM_String *notationName; } Entity; struct { DOM_String *target; DOM_String *data; } ProcessingInstruction; } u; };
The DOM_Node_insertBefore function
Description
#include <domc.h> DOM_Node *DOM_Node_insertBefore(DOM_Node *this, DOM_Node *newChild, DOM_Node *refChild);
The DOM_Node_replaceChild function
Description
#include <domc.h> DOM_Node *DOM_Node_replaceChild(DOM_Node *this, DOM_Node *newChild, DOM_Node *oldChild);
If newChild is a DocumentFragment object, oldChild is replaced by all of the DocumentFragment children, which are inserted in the same order. If the newChild is already in the tree, it is first removed.
The DOM_Node_removeChild function
Description
#include <domc.h> DOM_Node *DOM_Node_removeChild(DOM_Node *this, DOM_Node *oldChild);
The DOM_Node_appendChild function
Description
#include <domc.h> DOM_Node *DOM_Node_appendChild(DOM_Node *this, DOM_Node *newChild);
The DOM_Node_hasChildNodes function
Description
#include <domc.h> int DOM_Node_hasChildNodes(DOM_Node *this);
The DOM_Node_cloneNode function
Description
#include <domc.h> DOM_Node *DOM_Node_cloneNode(DOM_Node *this, int deep);
The DOM specification requires that cloning an attribute node directly will return a specified attribute opposed to an attribute resulting from a default value specified in the DTD. Currently DOMC does not consider DTD default values. The value of attr->u.Attr.specified will always be 0.
The DOM_Node_normalize function
Description
#include <domc.h> void DOM_Node_normalize(DOM_Node *this);