From 7233f9f6b42282c407d584e92578bae4b1eb7cb1 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 26 Jul 2007 13:17:08 +0000 Subject: Add ability to set a document's doctype after the document has been created svn path=/trunk/dom/; revision=3462 --- bindings/xml/xmlparser.c | 11 ++++++++--- include/dom/bootstrap/implpriv.h | 7 +++++++ src/core/document.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/bindings/xml/xmlparser.c b/bindings/xml/xmlparser.c index 5c63b29..9e907d6 100644 --- a/bindings/xml/xmlparser.c +++ b/bindings/xml/xmlparser.c @@ -13,6 +13,7 @@ #include #include +#include #include #include "xmlerror.h" @@ -1089,9 +1090,13 @@ void xml_parser_add_document_type(xml_parser *parser, dom_string_unref(public_id); dom_string_unref(qname); - /** \todo Add doctype to document (requires some libdom-internal API - * -- doctypes are immutable in the DOM) */ - UNUSED(parent); + /* Add doctype to document */ + err = dom_document_set_doctype((struct dom_document *) parent, + doctype); + if (err != DOM_NO_ERR) { + dom_node_unref((struct dom_node *) doctype); + return; + } /* Link nodes together */ err = xml_parser_link_nodes(parser, (struct dom_node *) doctype, diff --git a/include/dom/bootstrap/implpriv.h b/include/dom/bootstrap/implpriv.h index aa123e0..d9cc787 100644 --- a/include/dom/bootstrap/implpriv.h +++ b/include/dom/bootstrap/implpriv.h @@ -12,6 +12,9 @@ * The DOMImplementation and DOMImplementationList implementations also * include this, as those types are defined here. * + * The Document implementation includes this as it needs the declaration of + * dom_document_set_doctype. + * * No other client should be including this. */ @@ -241,4 +244,8 @@ struct dom_implementation_source { dom_exception dom_register_source(struct dom_implementation_source *source, dom_alloc alloc, void *pw); +/* Set a Document's DocumentType */ +dom_exception dom_document_set_doctype(struct dom_document *doc, + struct dom_document_type *doctype); + #endif diff --git a/src/core/document.c b/src/core/document.c index b73f5e3..0552c22 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -6,6 +6,7 @@ */ #include +#include #include #include "core/characterdata.h" @@ -752,6 +753,35 @@ dom_exception dom_document_rename_node(struct dom_document *doc, return DOM_NOT_SUPPORTED_ERR; } +/* */ +/* ----------------------------------------------------------------------- */ +/* */ + +/** + * 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