[All Packages] [Next]
The Document Object Model (DOM) is an application programming interface (API) for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. In the DOM specification, the term document is used in the broad sense -- increasingly, XML is being used as a way of representing many different kinds of information that may be stored in diverse systems, and much of this would traditionally be seen as data rather than as documents. Nevertheless, XML presents this data as documents, and the DOM may be used to manage this data.
With the DOM, programmers can build documents, navigate their structure, and add, modify, or delete elements and content. Anything found in an HTML or XML document can be accessed, changed, deleted, or added using the DOM, with a few exceptions -- in particular, the DOM interfaces for the XML internal and external subsets have not yet been specified.
One important objective of the W3C specification for the DOM is to provide a standard programming interface that can be used in a wide variety of environments and applications. The DOM is designed to be used with any programming language. Since the DOM standard is object-oriented, for this C adaptation, some changes had to be made:
The implementation of this C DOM interface follows REC-DOM-Level-1-19981001.
| boolean | Boolean value, TRUE or FALSE |
| oratext | String pointer |
| xmlcpmod | Content model node modifier |
| xmlctx | Master XML parser context |
| xmlnode | Document node |
| xmlnodes | Array of nodes |
| xmlntype | Node type enumeration |
| appendChild | Append child node to current node |
| appendData | Append character data to end of node's current data |
| cloneNode | Create a new node identical to the current one |
| createAttribute | Create an new attribute for an element node |
| createCDATASection | Create a CDATA_SECTION node |
| createComment | Create a COMMENT node |
| createDocumentFragment | Create a DOCUMENT_FRAGMENT node |
| createElement | Create an ELEMENT node |
| createEntityReference | Create an ENTITY_REFERENCE node |
| createProcessingInstruction | Create a PROCESSING_INSTRUCTION (PI) node |
| createTextNode | Create a TEXT node |
| deleteData | Remove substring from a node's character data |
| getAttrName | Return an attribute's name |
| getAttrSpecified | Return value of attribute's specified flag [DOM getSpecified] |
| getAttrValue | Return an attribute's value (definition) [DOM getValue] |
| getAttribute | Return the value of an attribute |
| getAttributeIndex | Return an element's attribute given its index |
| getAttributeNode | Get an element's attribute node given its name [DOM getName] |
| getAttributes | Return array of element's attributes |
| getCharData | Return character data for a TEXT node [DOM getData] |
| getCharLength | Return length of TEXT node's character data [DOM getLength] |
| getChildNode | Return indexed node from array of nodes [DOM item] |
| getChildNodes | Return array of node's children |
| getContentModel | Returns the content model for an element from the DTD [DOM extension] |
| getDocument | Return top-level DOCUMENT node [DOM extension] |
| getDocumentElement | Return highest-level (root) ELEMENT node |
| getDocType | Return current DTD |
| getDocTypeEntities | Return array of DTD's general entities |
| getDocTypeName | Return name of DTD |
| getDocTypeNotations | Return array of DTD's notations |
| getElementsByTagName | Return list of elements with matching name |
| getEntityNotation | Return an entity's NDATA [DOM getNotation] |
| getEntityPubID | Return an entity's public ID [DOM getPublicId] |
| getEntitySysID | Return an entity's system ID [DOM getSystemId] |
| getFirstChild | Return the first child of a node |
| getImplementation | Return DOM-implementation structure (if defined) |
| getLastChild | Return the last child of a node |
| getModifier | Returns a content model node's '?', '*', or '+' modifier [DOM extension] |
| getNextSibling | Return a node's next sibling |
| getNamedItem | Returns the named node from a list of nodes |
| getNodeMapLength | Returns number of entries in a NodeMap [DOM getLength] |
| getNodeName | Returns a node's name |
| getNodeType | Returns a node's type code (enumeration) |
| getNodeValue | Returns a node's "value", its character data |
| getNotationPubID | Returns a notation's public ID [DOM getPublicId] |
| getNotationSysID | Returns a notation's system ID [DOM getSystemId] |
| getOwnerDocument | Returns the DOCUMENT node containing the given node |
| getPIData | Returns a processing instruction's data [DOM getData] |
| getPITarget | Returns a processing instruction's target [DOM getTarget] |
| getParentNode | Returns a node's parent node |
| getPreviousSibling | Returns a node's "previous" sibling |
| getTagName | Returns a node's "tagname", same as name for now |
| hasAttributes | Determine if element node has attributes [DOM extension] |
| hasChildNodes | Determine if node has children |
| hasFeature | Determine if DOM implementation supports a specific feature |
| insertBefore | Inserts a new child node before the given reference node |
| insertData | Inserts new character data into a node's existing data |
| isStandalone | Determine if document is standalone [DOM extension] |
| nodeValid | Validate a node against the current DTD [DOM extension] |
| normalize | Normalize a node by merging adjacent TEXT nodes |
| numAttributes | Returns number of element node's attributes [DOM extension] |
| numChildNodes | Returns number of node's children [DOM extension] |
| removeAttribute | Removes an element's attribute given its names |
| removeAttributeNode | Removes an element's attribute given its pointer |
| removeChild | Removes a node from its parents list of children |
| removeNamedItem | Removes a node from a list of nodes given its name |
| replaceChild | Replace one node with another |
| replaceData | Replace a substring of a node's character data with another string |
| setAttribute | Sets (adds or replaces) a new attribute for an element node given the attribute's name and value |
| setAttributeNode | Sets (adds or replaces) a new attribute for an element node given a pointer to the new attribute |
| setNamedItem | Sets (adds or replaces) a new node in a parent's list of children |
| setNodeValue | Sets a node's "value" (character data) |
| setPIData | Sets a processing instruction's data [DOM setData] |
| splitText | Split a node's character data into two parts |
| substringData | Return a substring of a node's character data |
typedef int boolean;
typedef unsigned char oratext;
XMLCPMOD_NONE = 0 /* no modifier */ XMLCPMOD_OPT = 1 /* '?' optional */ XMLCPMOD_0MORE = 2 /* '*' zero or more */ XMLCPMOD_1MORE = 3 /* '+' one or more */
typedef struct xmlctx xmlctx;
typedef struct xmlnode xmlnode;
typedef struct xmlnodes xmlnodes;
ELEMENT_NODE = 1 /* element */ ATTRIBUTE_NODE = 2 /* attribute */ TEXT_NODE = 3 /* char data not escaped by CDATA */ CDATA_SECTION_NODE = 4 /* char data escaped by CDATA */ ENTITY_REFERENCE_NODE = 5 /* entity reference */ ENTITY_NODE = 6 /* entity */ PROCESSING_INSTRUCTION_NODE = 7 /* processing instruction */ COMMENT_NODE = 8 /* comment */ DOCUMENT_NODE = 9 /* document */ DOCUMENT_TYPE_NODE = 10 /* DTD */ DOCUMENT_FRAGMENT_NODE = 11 /* document fragment */ NOTATION_NODE = 12 /* notation */
xmlnode *appendChild(xmlctx *ctx, xmlnode *parent, xmlnode *newnode)
| ctx | (IN) | XML context |
| parent | (IN) | parent node |
| newnode | (IN) | new node to append |
xmlnode *node, *parent;
...
if (node = createElement(ctx, "node"))
appendChild(ctx, parent, node);
void appendData(xmlctx *ctx, xmlnode *node, const oratext *arg)
| ctx | (IN) | XML context |
| node | (IN) | pointer to node |
| arg | (IN) | new data to append |
xmlnode *node; ... getNodeValue(node) -> "foo" appendData(ctx, node, "bar"); getNodeValue(node) -> "foobar"
xmlnode *cloneNode(xmlctx *ctx, const xmlnode *old, boolean deep)
| ctx | (IN) | XML context |
| old | (IN) | old node to clone |
| deep | (IN) | recursion flag |
xmlnode *createAttribute(xmlctx *ctx, const oratext *name, const oratext *value)
| ctx | (IN) | XML context |
| name | (IN) | name of new attribute |
| value | (IN) | value of new attribute |
xmlnode *attr, *elem;
...
if (attr = createAttribute(ctx, "attr1", "value1"))
{
setAttributeNode(ctx, elem, attr, NULL);
}
xmlnode *createCDATASection(xmlctx *ctx, const oratext *data)
| ctx | (IN) | XML context |
| data | (IN) | CDATA body |
xmlnode *node, *parent;
...
if (node = createCDATASection(ctx, "<greeting>H'o!</greeting>"))
appendChild(ctx, parent, node);
xmlnode *createComment(xmlctx *ctx, const oratext *data)
| ctx | (IN) | XML context |
| data | (IN) | text of comment |
xmlnode *node, *parent;
...
if (node = createComment(ctx, "From here on this document is unfinished"))
appendChild(ctx, parent, node);
xmlnode *createDocumentFragment(xmlctx *ctx)
| ctx | (IN) | XML context |
xmlnode *frag, *fragelem, *fragtext;
...
if ((frag = createDocumentFragment(ctx)) &&
(fragelem = createElement(ctx, (oratext *) "FragElem")) &&
(fragtext = createTextNode(ctx, (oratext *) "FragText")))
{
appendChild(ctx, frag, fragelem);
appendChild(ctx, frag, fragtext);
}
xmlnode *createElement(xmlctx *ctx, const oratext *elname)
| ctx | (IN) | XML context |
| elname | (IN) | name of new element |
xmlnode *node, *parent;
...
if (node = createElement(ctx, "BOOK"))
appendChild(ctx, parent, node);
xmlnode *createEntityReference(xmlctx *ctx, const oratext *name)
| ctx | (IN) | XML context |
| name | (IN) | name of entity to reference |
xmlnode *node, *parent;
...
if (node = createEntityReference(ctx, "homephone"))
appendChild(ctx, parent, node);
xmlnode *createProcessingInstruction(xmlctx *ctx, const oratext *target, const oratext *data)
| ctx | (IN) | XML context |
| target | (IN) | PI target |
| data | (IN) | PI definition |
xmlnode *node, *parent;
...
if (node = createProcessingInstruction(ctx, "target", "definition"))
appendChild(ctx, parent, node);
xmlnode *createTextNode(xmlctx *ctx, const oratext *data)
| ctx | (IN) | XML context |
| data | (IN) | data for node |
xmlnode *node, *parent;
...
if (node = createTextNode(ctx, "riverrun, past Eve and Adam's..."))
appendChild(ctx, parent, node);
void deleteData(xmlctx *ctx, xmlnode *node, ub4 offset, ub4 count)
| ctx | (IN) | XML context |
| node | (IN) | pointer to node |
| offset | (IN) | offset of start of substring (0 is first char) |
| count | (IN) | length of substring |
xmlnode *node; ... getNodeValue(node) -> "phoenix" deleteData(ctx, node, 2, 1); getNodeValue(node) -> "phenix"
const oratext *getAttribute(const xmlnode *node, const oratext *name)
| node | (IN) | node whose attribtutes to scan |
| name | (IN) | name of the attribute |
xmlnode *node, *attr;
xmlnodes *nodes;
const oratext *attrval;
...
if (nodes = getAttributes(node))
{
attr = getAttributeIndex(nodes, 1); /* second attribute */
attrval = getAttribute(attr, "foo");
...
}
xmlnode *getAttributeIndex(const xmlnodes *attrs, size_t index)
| attrs | (IN) | pointer to attribute nodes structure (as returned by getAttributes) |
| index | (IN) | zero-based attribute# to return |
xmlnode *node, *attr;
xmlnodes *nodes;
...
if (nodes = getAttributes(node))
{
attr = getAttributeIndex(nodes, 1); /* second attribute */
...
}
xmlnode *getAttributeNode(const xmlnode *elem, const oratext *name)
| elem | (IN) | pointer to element node |
| name | (IN) | name of attribute |
xmlnode *node, *attr;
...
if (attr = getAttributeNode(elem, "attr1"))
...
xmlnodes *getAttributes(const xmlnode *node)
| node | (IN) | node whose attributes to return |
xmlnode *node;
xmlnodes *nodes;
...
if (nodes = getAttributes(node))
...
const oratext *getAttrName(const xmlnode *attr)
| attr | (IN) | pointer to attribute (see getAttribute) |
xmlnode *elem, *attr; ... attr = setAttribute(ctx, elem, "x", "y"); getAttrName(attr) -> "x"
boolean getAttrSpecified(const xmlnode *attr)
| attr | (IN) | pointer to attribute (see getAttribute) |
xmlnode *elem, *attr; ... attr = setAttribute(ctx, elem, "x", "y"); getAttrSpecified(attr) -> TRUE
const oratext *getAttrValue(const xmlnode *attr)
| attr | (IN) | pointer to attribute (see getAttribute) |
xmlnode *elem, *attr; ... attr = setAttribute(ctx, elem, "x", "y"); getAttrValue(attr) -> "y"
const oratext *getCharData(const xmlnode *node)
| node | (IN) | pointer to text node |
xmlnode *node;
...
if (node = createTextNode(ctx, "riverrun"))
getCharData(node) -> "riverrun"
ub4 getCharLength(const xmlnode *node)
| node | (IN) | pointer to text node |
xmlnode *node;
...
if (node = createTextNode(ctx, "prumptly"))
getCharLength(node) -> 8
xmlnode* getChildNode(const xmlnodes *nodes, size_t index)
| nodes | (IN) | array of nodes (see getChildNodes) |
| index | (IN) | zero-based child# |
xmlnode *node, *child;
xmlnodes *nodes;
...
if (nodes = getChildNodes(node))
{
child = getChildNode(nodes, 1); /* second child node */
...
}
xmlnodes* getChildNodes(const xmlnode *node)
| node | (IN) | node whose children to return |
xmlnode *node;
xmlnodes *nodes;
...
if (nodes = getChildNodes(node))
...
xmlnode *LpxGetContentModel(xmldtd *dtd, oratext *name)
| dtd | (IN) | pointer to the DTD |
| name | (IN) | name of element |
xmldtd* getDocType(xmlctx *ctx)
| ctx | (IN) | XML parser context |
xmlnodes *nodes; ... nodes = getDocTypeEntities(getDocType(ctx));
xmlnodes *getDocTypeEntities(xmldtd* dtd)
| dtd | (IN) | pointer to DTD |
xmldtd *dtd; xmlnodes *entities; ... dtd = getDocType(ctx); entities = getDocTypeEntities(dtd);
oratext *getDocTypeName(xmldtd* dtd)
| dtd | (IN) | pointer to DTD |
xmlnodes *getDocTypeNotations(xmldtd* dtd)
| dtd | (IN) | pointer to DTD |
xmldtd *dtd; xmlnodes *notations; ... dtd = getDocType(ctx); notations = getDocTypeNotations(dtd);
xmlnodes *getElementsByTagName(xmlctx *ctx, xmlnode *root, const oratext *name)
| ctx | (IN) | XML parser context |
| root | (IN) | root node of tree |
| name | (IN) | element tag name |
xmlnodes *nodes; ... nodes = getElementsByTagName(ctx, NULL, "ACT"); /* find all ACT elements */
xmlnode* getDocument(xmlctx *ctx)
| ctx | (IN) | XML parser context |
xmlnode* getDocumentElement(xmlctx *ctx)
| ctx | (IN) | XML parser context |
const oratext *getEntityNotation(const xmlnode *ent)
| ent | (IN) | pointer to entity |
<!NOTATION n SYSTEM "http://www.w3.org/"> <!ENTITY e SYSTEM "http://www.w3.org/" NDATA n> xmlnode *ent; /* assume ent will be set to ENTITY node above */ ... getEntityNotation(ent) -> "n"
const oratext *getEntityPubID(const xmlnode *ent)
| ent | (IN) | pointer to entity |
<!ENTITY e PUBLIC "PublicID" "nop.ent"> xmlnode *ent; /* assume ent will be set to ENTITY node above */ ... getEntityPubID(ent) -> "PublicID"
const oratext *getEntitySysID(const xmlnode *ent)
| ent | (IN) | pointer to entity |
<!ENTITY e PUBLIC "PublicID" "nop.ent"> xmlnode *ent; /* assume ent will be set to ENTITY node above */ ... getEntitySysID(ent) -> "nop.ent"
xmlnode* getFirstChild(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing> xmlnode *elem; /* assume elem will point to element Thing */ ... getFirstChild(elem) -> element "A"
xmldomimp* getImplementation(xmlctx *ctx)
| ctx | (IN) | XML context |
xmlnode* getLastChild(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing> xmlnode *elem; /* assume elem will point to element Thing */ ... getLastChild(elem) -> element "C"
xmlcpmod getModifier(xmlnode *node)
| node | (IN) | pointer to content model node |
xmlnode *getNamedItem(const xmlnodes *nodes, const oratext *name, size_t *index)
| nodes | (IN) | array of nodes |
| name | (IN) | name of node to fetch |
| index | (OUT) | index of found node |
xmlnode *node, *elem;
xmlnodes *nodes;
size_t index;
...
if (nodes = getChildNodes(elem))
{
node = getNamedItem(nodes, "FOO", &index);
...
}
xmlnode* getNextSibling(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing>
xmlnode *node, *elem; /* assume elem will point to node Thing */
...
for (node = getFirstChild(elem); node; node = getNextSibling(node))
...node will be A then B then C...
size_t getNodeMapLength(const xmlnodes *nodes)
| nodes | (IN) | array of nodes |
<Thing><A/><B/><C/></Thing>
xmlnodes *nodes;
xmlnode *elem; /* assume elem will point to node Thing */
...
if (nodes = getChildNodes(elem))
getNodeMapLength(nodes) -> 3
const oratext* getNodeName(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing> xmlnode *elem; /* assume elem will point to node Thing */ ... getNodeName(elem) -> "Thing"
xmlntype getNodeType(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing> xmlnode *elem; /* assume elem will point to node Thing */ ... getNodeType(elem) -> ELEMENT_NODE
const oratext* getNodeValue(const xmlnode *node)
| node | (IN) | pointer to node |
<!--This is a comment--> xmlnode *node; /* assume node will point to comment node above */ ... getNodeValue(node) -> "This is a comment"
const oratext *getNotationPubID(const xmlnode *note)
| note | (IN) | pointer to node |
<!NOTATION n PUBLIC "whatever"> xmlnode *note; /* assume note will point to notation node above */ ... getNotationPubID(note) -> "whatever"
const oratext *getNotationSysID(const xmlnode *note)
| note | (IN) | pointer to node |
<!NOTATION n SYSTEM "http://www.w3.org/"> xmlnode *note; /* assume note will point to notation node above */ ... getNotationSysID(note) -> "http://www.w3.org/"
xmlnode* getOwnerDocument(xmlnode *node)
| node | (IN) | pointer to node |
xmlnode* getParentNode(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing> xmlnode *elem; /* assume elem will point to node A */ ... getParentNode(elem) -> node Thing
const oratext *getPIData(const xmlnode *pi)
| pi | (IN) | pointer to PI node |
<?PI Blither blather?> xmlnode *pi; /* assume pi will point to PI node above */ ... getPIData(pi) -> "Blither blather"
const oratext *getPITarget(const xmlnode *pi)
| pi | (IN) | pointer to PI node |
<?PI Blither blather?> xmlnode *pi; /* assume pi will point to PI node above */ ... getPITarget(pi) -> "PI"
xmlnode* getPreviousSibling(const xmlnode *node)
| node | (IN) | pointer to node |
<Thing><A/><B/><C/></Thing>
xmlnode *node, *elem; /* assume elem will point to node Thing */
...
for (node = getLastChild(elem); node; node = getPreviousSibling(node))
...node will be C then B then A...
const oratext *getTagName(const xmlnode *node)
| node | (IN) | pointer to node |
boolean hasAttributes(const xmlnode *node)
| node | (IN) | pointer to node |
boolean hasChildNodes(const xmlnode *node)
| node | (IN) | pointer to node |
boolean hasFeature(xmlctx *ctx, const oratext *feature, const oratext *version)
| ctx | (IN) | XML context |
| feature | (IN) | the package name of the feature to test |
| version | (IN) | the version number of the package name to test |
xmlnode *insertBefore(xmlctx *ctx, xmlnode *parent, xmlnode *newChild, xmlnode *refChild)
| ctx | (IN) | XML context |
| parent | (IN) | parent node to insert into |
| newChild | (IN) | new child node to insert |
| refChild | (IN) | reference node to insert before |
<Thing><A/><B/><C/></Thing>
xmlnode *elem, *new, *ref; /* assume elem points to Thing, new is a new
element "Z", and ref points to node B */
...
insertBefore(ctx, elem, new, ref);
<Thing><A/><Z/><B/><C/></Thing>
void insertData(xmlctx *ctx, xmlnode *node, ub4 offset, const oratext *arg)
| ctx | (IN) | XML context |
| node | (IN) | pointer to node |
| offset | (IN) | insertion point (0 is first position) |
| refChild | (IN) | new string to insert |
xmlnode *node; ... getNodeValue(node) -> "abcdefg" insertData(ctx, node, 3, "ZZZ"); getNodeValue(node) -> "abcZZZdefg"
boolean isStandalone(xmlctx *ctx)
| ctx | (IN) | XML parser context |
uword nodeValid(xmlctx *ctx, const xmlnode *node)
| ctx | (IN) | XML context |
| node | (IN) | pointer to node |
void normalize(xmlctx *ctx, xmlnode *elem)
| ctx | (IN) | XML context |
| elem | (IN) | pointer to element node |
xmlnode *node, *t1, *t2;
...
if ((node = createElement(ctx, "FOO")) &&
(t1 = createTextNode(ctx, "one of ")) &&
(t2 = createTextNode(ctx, "these days")) &&
appendChild(ctx, node, t1) &&
appendChild(ctx, node, t2))
{
<FOO>"one of " "these days"</FOO>
normalize(ctx, node);
<FOO>"one of these days"</FOO>
}
size_t numAttributes(const xmlnodes *attrs)
| attrs | (IN) | array of attributes |
xmlnodes *nodes;
xmlnode *node;
size_t i;
...
if (nodes = getAttributes(node))
{
for (i = 0; i < numAttributes(nodes); i++)
...
}
size_t numChildNodes(const xmlnodes *nodes)
| nodes | (IN) | pointer to opaque nodes structure |
xmlnodes *nodes;
xmlnode *elem;
size_t i;
...
if (nodes = getChildNodes(elem))
{
for (i = 0; i < numChildNodes(nodes); i++)
...
}
void removeAttribute(xmlnode *elem, const oratext *name)
| elem | (IN) | pointer to element node |
| name | (IN) | name of attribute to remove |
<!ATTLIST FOO attr CDATA 'default'> xmlnode *elem; /* assume elem point to a FOO node */ ... <FOO attr="snark"/> removeAttribute(elem, "attr"); <FOO attr="default"/>
xmlnode *removeAttributeNode(xmlnode *elem, xmlnode *attr)
| elem | (IN) | pointer to element node |
| attr | (IN) | attribute node to remove |
xmlnode *elem, *attr;
...
if (attr = getAttributeNode(elem, "attr1"))
removeAttributeNode(elem, attr);
xmlnode *removeChild(xmlnode *node)
| node | (IN) | old node to remove |
xmlnodes *nodes;
xmlnode *elem, *node;
...
if ((nodes = getChildNodes(elem)) &&
(node = getNamedItem(nodes, "B", NULL))
{
<Thing><A/><B/><C/></Thing>
removeChild(node);
<Thing><A/><C/></Thing>
}
xmlnode *removeNamedItem(xmlnodes *nodes, const oratext *name)
| nodes | (IN) | list of nodes |
| name | (IN) | name of node to remove |
xmlnodes *nodes;
xmlnode *elem;
...
if (nodes = getChildNodes(elem))
{
<Thing><A/><B/><C/></Thing>
removeNamedItem(nodes, "B");
<Thing><A/><C/></Thing>
}
xmlnode *replaceChild(xmlctx *ctx, xmlnode *newChild, xmlnode *oldChild)
| ctx | (IN) | XML context |
| newChild | (IN) | new replacement node |
| oldChild | (IN) | old node being replaced |
xmlnodes *nodes;
xmlnode *elem, *old, *new;
...
if ((nodes = getChildNodes(elem)) &&
(old = getNamedItem(nodes, "B", NULL)) &&
(new = createElement(ctx, "NEW")))
{
<Thing><A/><B/><C/></Thing>
replaceChild(ctx, new, old);
<Thing><A/><NEW/><C/></Thing>
}
void replaceData(xmlctx *ctx, xmlnode *node, ub4 offset, ub4 count, oratext *arg)
| ctx | (IN) | XML context |
| node | (IN) | pointer to node |
| offset | (IN) | start of substring to replace (0 is first character) |
| count | (IN) | length of old substring |
| arg | (IN) | replacement text |
xmlnode *node; ... getNodeValue(node) -> "every dog has his day" replaceData(ctx, node, 6, 3, "man"); getNodeValue(node) -> "every man has his day"
xmlnode *setAttribute(xmlctx *ctx, xmlnode *elem, const oratext *name, const oratext *value)
| ctx | (IN) | XML context |
| elem | (IN) | pointer to element node |
| name | (IN) | name of new attribute |
| value | (IN) | value of new attribute |
xmlnode *elem; ... <Thing/> setAttribute(ctx, elem, "attr", "value"); <Thing attr="value"/>
boolean setAttributeNode(xmlctx *ctx, xmlnode *elem,
xmlnode *newNode, xmlnode **oldNode)
| ctx | (IN) | XML context |
| elem | (IN) | pointer to element node |
| newNode | (IN) | pointer to new attribute |
| oldNode | (OUT) | return pointer for old attribute |
xmlnode *elem, *attr;
...
if (attr = createAttribute(ctx, "attr", "value"))
{
<Thing/>
setAttributeNode(ctx, elem, attr, NULL);
<Thing attr="value"/>
}
boolean setNamedItem(xmlctx *ctx, xmlnode *parent, xmlnode *node, xmlnode **old)
| node | (IN) | pointer to node |
| parent | (IN) | parent to add node to |
| node | (IN) | new node to add |
| old | (IN) | pointer to replaced node |
xmlnode *elem, *new;
...
if ((new = createElement(ctx, "B")) &&
setAttribute(ctx, new, "attr", "value"))
{
<Thing><A/><B/><C/></Thing>
setNamedItem(ctx, elem, new, NULL);
<Thing><A/><B attr="value"/><C/></Thing>
}
boolean setNodeValue(xmlnode *node, const oratext *data)
| node | (IN) | pointer to node |
| data | (IN) | new data for node |
xmlnode *node; ... getNodeValue(node) -> "umbrella" setNodeValue(node, "brolly"); getNodeValue(node) -> "brolly"
void setPIData(xmlnode *pi, const oratext *data)
| pi | (IN) | pointer to PI node |
| data | (IN) | new data for PI |
xmlnode *pi; ... <?SKRINKLIT Monster Grendel's tastes are plainish?> setPIData(pi, "Breakfast? Just a couple Danish."); <?SKRINKLIT Breakfast? Just a couple Danish.?>
xmlnode *splitText(xmlctx *ctx, xmlnode *old, uword offset)
| ctx | (IN) | XML context |
| old | (IN) | original node to split |
| offset | (IN) | offset of split point |
xmlnode *node; ... <FOO>"one of these days"</FOO> splitText(ctx, node, 7); <FOO>"one of " "these days"</FOO>
const oratext *substringData(xmlctx *ctx, const xmlnode *node, ub4 offset, ub4 count)
| ctx | (IN) | XML context |
| node | (IN) | pointer to node |
| offset | (IN) | offset of start of substring |
| count | (IN) | length of substring |
xmlnode *node; ... <FOO>"one of these days"</FOO> substringData(ctx, node, 0, 3) -> "one"