From 7b83a0bb1cd4604ab6a55705c4b1c40c769090a6 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 27 Sep 2007 23:03:13 +0000 Subject: Modify dom_node_initialise() API to permit specification of namespace URI and prefix. Fix up everything else to cope. svn path=/trunk/dom/; revision=3599 --- src/core/attr.c | 13 ++++++++----- src/core/attr.h | 3 ++- src/core/characterdata.c | 3 ++- src/core/doc_fragment.c | 2 +- src/core/document.c | 6 +++--- src/core/document_type.c | 2 +- src/core/element.c | 18 +++++++++++------- src/core/element.h | 3 ++- src/core/entity_ref.c | 2 +- src/core/node.c | 30 ++++++++++++++++++++---------- src/core/node.h | 3 ++- src/core/pi.c | 2 +- 12 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/core/attr.c b/src/core/attr.c index dbf2fc2..232f7ba 100644 --- a/src/core/attr.c +++ b/src/core/attr.c @@ -39,9 +39,11 @@ struct dom_attr { /** * Create an attribute node * - * \param doc The owning document - * \param name The name of the node to create - * \param result Pointer to location to receive created attribute + * \param doc The owning document + * \param name The (local) name of the node to create + * \param namespace The namespace URI of the attribute, or NULL + * \param prefix The namespace prefix of the attribute, or NULL + * \param result Pointer to location to receive created attribute * \return DOM_NO_ERR on success, * DOM_INVALID_CHARACTER_ERR if ::name is invalid, * DOM_NO_MEM_ERR on memory exhaustion. @@ -51,7 +53,8 @@ struct dom_attr { * The returned attribute will already be referenced. */ dom_exception dom_attr_create(struct dom_document *doc, - struct dom_string *name, struct dom_attr **result) + struct dom_string *name, struct dom_string *namespace, + struct dom_string *prefix, struct dom_attr **result) { struct dom_attr *a; dom_exception err; @@ -65,7 +68,7 @@ dom_exception dom_attr_create(struct dom_document *doc, /* Initialise the base class */ err = dom_node_initialise(&a->base, doc, DOM_ATTRIBUTE_NODE, - name, NULL); + name, NULL, namespace, prefix); if (err != DOM_NO_ERR) { dom_document_alloc(doc, a, 0); return err; diff --git a/src/core/attr.h b/src/core/attr.h index dc73ae0..bf5a606 100644 --- a/src/core/attr.h +++ b/src/core/attr.h @@ -15,7 +15,8 @@ struct dom_attr; struct dom_string; dom_exception dom_attr_create(struct dom_document *doc, - struct dom_string *name, struct dom_attr **result); + struct dom_string *name, struct dom_string *namespace, + struct dom_string *prefix, struct dom_attr **result); void dom_attr_destroy(struct dom_document *doc, struct dom_attr *attr); #endif diff --git a/src/core/characterdata.c b/src/core/characterdata.c index 9cf3a49..91aa93d 100644 --- a/src/core/characterdata.c +++ b/src/core/characterdata.c @@ -28,7 +28,8 @@ dom_exception dom_characterdata_initialise(struct dom_characterdata *cdata, struct dom_document *doc, dom_node_type type, struct dom_string *name, struct dom_string *value) { - return dom_node_initialise(&cdata->base, doc, type, name, value); + return dom_node_initialise(&cdata->base, doc, type, + name, value, NULL, NULL); } /** diff --git a/src/core/doc_fragment.c b/src/core/doc_fragment.c index eaef388..b6dbd26 100644 --- a/src/core/doc_fragment.c +++ b/src/core/doc_fragment.c @@ -45,7 +45,7 @@ dom_exception dom_document_fragment_create(struct dom_document *doc, /* And initialise the node */ err = dom_node_initialise(&f->base, doc, DOM_DOCUMENT_FRAGMENT_NODE, - name, value); + name, value, NULL, NULL); if (err != DOM_NO_ERR) { dom_document_alloc(doc, f, 0); return err; diff --git a/src/core/document.c b/src/core/document.c index aedf96c..e1fc32b 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -142,7 +142,7 @@ dom_exception dom_document_create(struct dom_implementation *impl, * rest of the code, as it doesn't need to special case Documents) */ err = dom_node_initialise(&d->base, d, DOM_DOCUMENT_NODE, - NULL, NULL); + NULL, NULL, NULL, NULL); if (err != DOM_NO_ERR) { /* Clean up interned strings */ for (int i = 0; i <= DOM_NODE_TYPE_COUNT; i++) { @@ -330,7 +330,7 @@ dom_exception dom_document_get_document_element(struct dom_document *doc, dom_exception dom_document_create_element(struct dom_document *doc, struct dom_string *tag_name, struct dom_element **result) { - return dom_element_create(doc, tag_name, result); + return dom_element_create(doc, tag_name, NULL, NULL, result); } /** @@ -450,7 +450,7 @@ dom_exception dom_document_create_processing_instruction( dom_exception dom_document_create_attribute(struct dom_document *doc, struct dom_string *name, struct dom_attr **result) { - return dom_attr_create(doc, name, result); + return dom_attr_create(doc, name, NULL, NULL, result); } /** diff --git a/src/core/document_type.c b/src/core/document_type.c index 30d8fe2..73a8383 100644 --- a/src/core/document_type.c +++ b/src/core/document_type.c @@ -57,7 +57,7 @@ dom_exception dom_document_type_create(struct dom_string *qname, /* Initialise base node */ err = dom_node_initialise(&result->base, NULL, DOM_DOCUMENT_TYPE_NODE, - qname, NULL); + qname, NULL, NULL, NULL); if (err != DOM_NO_ERR) { alloc(result, 0, pw); return err; diff --git a/src/core/element.c b/src/core/element.c index 027d597..cf6a3f4 100644 --- a/src/core/element.c +++ b/src/core/element.c @@ -32,19 +32,23 @@ struct dom_element { /** * Create an element node * - * \param doc The owning document - * \param name The name of the node to create - * \param result Pointer to location to receive created element + * \param doc The owning document + * \param name The (local) name of the node to create + * \param namespace The namespace URI of the element, or NULL + * \param prefix The namespace prefix of the element, or NULL + * \param result Pointer to location to receive created element * \return DOM_NO_ERR on success, * DOM_INVALID_CHARACTER_ERR if ::name is invalid, * DOM_NO_MEM_ERR on memory exhaustion. * - * ::doc and ::name will have their reference counts increased. + * ::doc, ::name, ::namespace and ::prefix will have their + * reference counts increased. * * The returned element will already be referenced. */ dom_exception dom_element_create(struct dom_document *doc, - struct dom_string *name, struct dom_element **result) + struct dom_string *name, struct dom_string *namespace, + struct dom_string *prefix, struct dom_element **result) { struct dom_element *el; dom_exception err; @@ -58,7 +62,7 @@ dom_exception dom_element_create(struct dom_document *doc, /* Initialise the base class */ err = dom_node_initialise(&el->base, doc, DOM_ELEMENT_NODE, - name, NULL); + name, NULL, namespace, prefix); if (err != DOM_NO_ERR) { dom_document_alloc(doc, el, 0); return err; @@ -234,7 +238,7 @@ dom_exception dom_element_set_attribute(struct dom_element *element, dom_exception err; struct dom_attr *attr; - err = dom_attr_create(e->owner, name, &attr); + err = dom_attr_create(e->owner, name, NULL, NULL, &attr); if (err != DOM_NO_ERR) return err; diff --git a/src/core/element.h b/src/core/element.h index 95e7cfe..35e1323 100644 --- a/src/core/element.h +++ b/src/core/element.h @@ -19,7 +19,8 @@ struct dom_node; struct dom_string; dom_exception dom_element_create(struct dom_document *doc, - struct dom_string *name, struct dom_element **result); + struct dom_string *name, struct dom_string *namespace, + struct dom_string *prefix, struct dom_element **result); void dom_element_destroy(struct dom_document *doc, struct dom_element *element); diff --git a/src/core/entity_ref.c b/src/core/entity_ref.c index bf4868b..18e3a3a 100644 --- a/src/core/entity_ref.c +++ b/src/core/entity_ref.c @@ -46,7 +46,7 @@ dom_exception dom_entity_reference_create(struct dom_document *doc, /* And initialise the node */ err = dom_node_initialise(&e->base, doc, DOM_ENTITY_REFERENCE_NODE, - name, value); + name, value, NULL, NULL); if (err != DOM_NO_ERR) { dom_document_alloc(doc, e, 0); return err; diff --git a/src/core/node.c b/src/core/node.c index 2a90df8..8eff2ec 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -130,18 +130,22 @@ void dom_node_destroy(struct dom_node *node) /** * Initialise a DOM node * - * \param node The node to initialise - * \param doc The document which owns the node - * \param type The node type required - * \param name The node name, or NULL - * \param value The node value, or NULL + * \param node The node to initialise + * \param doc The document which owns the node + * \param type The node type required + * \param name The node (local) name, or NULL + * \param value The node value, or NULL + * \param namespace Namespace URI to use for node, or NULL + * \param prefix Namespace prefix to use for node, or NULL * \return DOM_NO_ERR on success. * - * ::name and ::value will have their reference counts increased. + * ::name, ::value, ::namespace, and ::prefix will have their reference + * counts increased. */ dom_exception dom_node_initialise(struct dom_node *node, struct dom_document *doc, dom_node_type type, - struct dom_string *name, struct dom_string *value) + struct dom_string *name, struct dom_string *value, + struct dom_string *namespace, struct dom_string *prefix) { if (name != NULL) dom_string_ref(name); @@ -179,9 +183,15 @@ dom_exception dom_node_initialise(struct dom_node *node, */ node->owner = doc; - /** \todo Namespace handling */ - node->namespace = NULL; - node->prefix = NULL; + if (namespace != NULL) { + dom_string_ref(namespace); + } + node->namespace = namespace; + + if (prefix != NULL) { + dom_string_ref(prefix); + } + node->prefix = prefix; node->user_data = NULL; diff --git a/src/core/node.h b/src/core/node.h index fd23625..277c441 100644 --- a/src/core/node.h +++ b/src/core/node.h @@ -57,7 +57,8 @@ void dom_node_destroy(struct dom_node *node); dom_exception dom_node_initialise(struct dom_node *node, struct dom_document *doc, dom_node_type type, - struct dom_string *name, struct dom_string *value); + struct dom_string *name, struct dom_string *value, + struct dom_string *namespace, struct dom_string *prefix); void dom_node_finalise(struct dom_document *doc, struct dom_node *node); diff --git a/src/core/pi.c b/src/core/pi.c index c2b6cc9..add2829 100644 --- a/src/core/pi.c +++ b/src/core/pi.c @@ -46,7 +46,7 @@ dom_exception dom_processing_instruction_create(struct dom_document *doc, /* And initialise the node */ err = dom_node_initialise(&p->base, doc, DOM_PROCESSING_INSTRUCTION_NODE, - name, value); + name, value, NULL, NULL); if (err != DOM_NO_ERR) { dom_document_alloc(doc, p, 0); return err; -- cgit v1.2.3