From b2256675eaf9cf9fa239da93db4f205d97fc710c Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 19 Sep 2007 22:06:26 +0000 Subject: Begin implementation of DocumentType class Remove dom_document_set_doctype() -- dom_node_insert_before() (and thus _append_child()) can be used to achieve the same effect. DocumentType node is now a child of the Document node (as it should have been) rather than a hidden field. Make dom_node_destroy() aware of DocumentType nodes potentially having no owner. Make dom_node_finalise() aware of it, too. Make dom_node_get_owner_document() return NULL for Document nodes, as per the spec. Fix bug in dom_node_insert_before() -- previously it failed to catch attempts to insert a second root element. Make dom_node_insert_before() handle DocumentType nodes appropriately. Implement XML binding's dom_implementation_create_document_type() function. Fix XML binding's dom_implementation_create_document() implementation to cope with changed API relating to doctype insertion. Fix up XML parser wrapper to cater for new doctype insertion mechanism. Also sprinkle some NULL about for paranoia purposes. svn path=/trunk/dom/; revision=3551 --- src/core/document.c | 51 ++++++++++----------------------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) (limited to 'src/core/document.c') diff --git a/src/core/document.c b/src/core/document.c index de57f72..d768946 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -55,8 +55,6 @@ struct dom_doc_nnm { struct dom_document { struct dom_node base; /**< Base node */ - struct dom_document_type *type; /**< Associated doctype */ - struct dom_implementation *impl; /**< Owning implementation */ struct dom_doc_nl *nodelists; /**< List of active nodelists */ @@ -157,8 +155,6 @@ dom_exception dom_document_create(struct dom_implementation *impl, } /* Initialise remaining type-specific data */ - d->type = NULL; - if (impl != NULL) dom_implementation_ref(impl); d->impl = impl; @@ -211,15 +207,6 @@ void dom_document_destroy(struct dom_document *doc) /* Ok, the document tree is empty, as is the list of nodes pending * deletion. Therefore, it is safe to destroy the document. */ - /* Destroy the doctype (if there is one) */ - if (doc->type != NULL) { - ((struct dom_node *) doc->type)->parent = NULL; - - dom_node_destroy((struct dom_node *) doc->type); - } - - doc->type = NULL; - if (doc->impl != NULL) dom_implementation_unref(doc->impl); doc->impl = NULL; @@ -258,10 +245,17 @@ void dom_document_destroy(struct dom_document *doc) dom_exception dom_document_get_doctype(struct dom_document *doc, struct dom_document_type **result) { - if (doc->type != NULL) - dom_node_ref((struct dom_node *) doc->type); + struct dom_node *c; - *result = doc->type; + for (c = doc->base.first_child; c != NULL; c = c->next) { + if (c->type == DOM_DOCUMENT_TYPE_NODE) + break; + } + + if (c != NULL) + dom_node_ref(c); + + *result = (struct dom_document_type *) c; return DOM_NO_ERR; } @@ -940,31 +934,6 @@ dom_exception dom_document_rename_node(struct dom_document *doc, /* ----------------------------------------------------------------------- */ /* */ -/** - * Set a Document's Document Type - * - * \param doc Document to set type of - * \param doctype The doctype to apply - * \return DOM_NO_ERR on success, - * DOM_INVALID_MODIFICATION_ERR if ::doc already has a doctype. - * - * The doctype will have its reference count increased. It is the - * responsibility of the caller to unref the doctype once it has finished - * with it. - */ -dom_exception dom_document_set_doctype(struct dom_document *doc, - struct dom_document_type *doctype) -{ - UNUSED(doc); - UNUSED(doctype); - - return DOM_NOT_SUPPORTED_ERR; -} - -/* */ -/* ----------------------------------------------------------------------- */ -/* */ - /** * Acquire a pointer to the base of the document buffer * -- cgit v1.2.3