summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-07-28 14:34:59 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-07-28 14:34:59 +0000
commit7cbcc882de7d5747e2342f0829bbcc9f2bcca60f (patch)
treed3fe522992dec910758c2b86d0d02ec9c2d005a9
parent6d0ecccfcf47341393d66e2379ce82cb8350a20f (diff)
downloadlibdom-7cbcc882de7d5747e2342f0829bbcc9f2bcca60f.tar.gz
libdom-7cbcc882de7d5747e2342f0829bbcc9f2bcca60f.tar.bz2
Sort out somewhat messy object construction.
We now have explicit types for all classes (rather than using the parent class for those which inherit but add no extra data content). svn path=/trunk/dom/; revision=3465
-rw-r--r--bindings/xml/xmlparser.c6
-rw-r--r--include/dom/core/document.h17
-rw-r--r--src/core/Makefile7
-rw-r--r--src/core/cdatasection.c56
-rw-r--r--src/core/cdatasection.h21
-rw-r--r--src/core/characterdata.c39
-rw-r--r--src/core/characterdata.h4
-rw-r--r--src/core/comment.c56
-rw-r--r--src/core/comment.h21
-rw-r--r--src/core/doc_fragment.c57
-rw-r--r--src/core/doc_fragment.h21
-rw-r--r--src/core/document.c34
-rw-r--r--src/core/entity_ref.c57
-rw-r--r--src/core/entity_ref.h21
-rw-r--r--src/core/node.c59
-rw-r--r--src/core/node.h4
-rw-r--r--src/core/pi.c58
-rw-r--r--src/core/pi.h21
-rw-r--r--src/core/text.c52
-rw-r--r--src/core/text.h21
20 files changed, 480 insertions, 152 deletions
diff --git a/bindings/xml/xmlparser.c b/bindings/xml/xmlparser.c
index 9e907d6..e140399 100644
--- a/bindings/xml/xmlparser.c
+++ b/bindings/xml/xmlparser.c
@@ -873,7 +873,7 @@ void xml_parser_add_text_node(xml_parser *parser, struct dom_node *parent,
void xml_parser_add_cdata_section(xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
- struct dom_text *cdata, *ins_cdata;
+ struct dom_cdata_section *cdata, *ins_cdata;
struct dom_string *data;
dom_exception err;
@@ -927,7 +927,7 @@ void xml_parser_add_cdata_section(xml_parser *parser,
void xml_parser_add_entity_reference(xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
- struct dom_node *entity, *ins_entity;
+ struct dom_entity_reference *entity, *ins_entity;
struct dom_string *name;
xmlNodePtr c;
dom_exception err;
@@ -988,7 +988,7 @@ void xml_parser_add_entity_reference(xml_parser *parser,
void xml_parser_add_comment(xml_parser *parser, struct dom_node *parent,
xmlNodePtr child)
{
- struct dom_characterdata *comment, *ins_comment;
+ struct dom_comment *comment, *ins_comment;
struct dom_string *data;
dom_exception err;
diff --git a/include/dom/core/document.h b/include/dom/core/document.h
index 6d79d28..cce8e4b 100644
--- a/include/dom/core/document.h
+++ b/include/dom/core/document.h
@@ -13,14 +13,19 @@
#include <dom/core/exceptions.h>
struct dom_attr;
+struct dom_cdata_section;
struct dom_characterdata;
+struct dom_comment;
struct dom_configuration;
struct dom_document;
+struct dom_document_fragment;
struct dom_document_type;
struct dom_element;
+struct dom_entity_reference;
struct dom_implementation;
struct dom_node;
struct dom_nodelist;
+struct dom_processing_instruction;
struct dom_string;
struct dom_text;
@@ -33,20 +38,22 @@ 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);
dom_exception dom_document_create_document_fragment(struct dom_document *doc,
- struct dom_node **result);
+ struct dom_document_fragment **result);
dom_exception dom_document_create_text_node(struct dom_document *doc,
struct dom_string *data, struct dom_text **result);
dom_exception dom_document_create_comment(struct dom_document *doc,
- struct dom_string *data, struct dom_characterdata **result);
+ struct dom_string *data, struct dom_comment **result);
dom_exception dom_document_create_cdata_section(struct dom_document *doc,
- struct dom_string *data, struct dom_text **result);
+ struct dom_string *data, struct dom_cdata_section **result);
dom_exception dom_document_create_processing_instruction(
struct dom_document *doc, struct dom_string *target,
- struct dom_string *data, struct dom_node **result);
+ struct dom_string *data,
+ struct dom_processing_instruction **result);
dom_exception dom_document_create_attribute(struct dom_document *doc,
struct dom_string *name, struct dom_attr **result);
dom_exception dom_document_create_entity_reference(struct dom_document *doc,
- struct dom_string *name, struct dom_node **result);
+ struct dom_string *name,
+ struct dom_entity_reference **result);
dom_exception dom_document_get_elements_by_tag_name(struct dom_document *doc,
struct dom_string *tagname, struct dom_nodelist **result);
dom_exception dom_document_import_node(struct dom_document *doc,
diff --git a/src/core/Makefile b/src/core/Makefile
index ee9b377..3084012 100644
--- a/src/core/Makefile
+++ b/src/core/Makefile
@@ -22,8 +22,11 @@
CFLAGS += -I$(CURDIR)
# Objects
-OBJS = attr characterdata document document_type element implementation impllist \
- namednodemap node nodelist string text
+OBJS = attr cdatasection characterdata comment \
+ document document_type doc_fragment \
+ element entity_ref implementation impllist \
+ namednodemap node nodelist \
+ pi string text
.PHONY: clean debug distclean export release setup test
diff --git a/src/core/cdatasection.c b/src/core/cdatasection.c
new file mode 100644
index 0000000..c477dd7
--- /dev/null
+++ b/src/core/cdatasection.c
@@ -0,0 +1,56 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "core/cdatasection.h"
+#include "core/document.h"
+#include "core/text.h"
+
+/**
+ * A DOM CDATA section
+ */
+struct dom_cdata_section {
+ struct dom_text base; /**< Base node */
+};
+
+/**
+ * Create a CDATA section
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_cdata_section_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_cdata_section **result)
+{
+ struct dom_cdata_section *c;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ c = dom_document_alloc(doc, NULL, sizeof(struct dom_cdata_section));
+ if (c == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_text_initialise(&c->base, doc, DOM_CDATA_SECTION_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, c, 0);
+ return err;
+ }
+
+ *result = c;
+
+ return DOM_NO_ERR;
+}
diff --git a/src/core/cdatasection.h b/src/core/cdatasection.h
new file mode 100644
index 0000000..c53985b
--- /dev/null
+++ b/src/core/cdatasection.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_cdatasection_h_
+#define dom_internal_core_cdatasection_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_cdata_section;
+struct dom_document;
+struct dom_string;
+
+dom_exception dom_cdata_section_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_cdata_section **result);
+
+#endif
diff --git a/src/core/characterdata.c b/src/core/characterdata.c
index 61275b5..7b38fd2 100644
--- a/src/core/characterdata.c
+++ b/src/core/characterdata.c
@@ -13,45 +13,6 @@
#include "utils/utils.h"
/**
- * Create a character data node of the given type
- *
- * \param doc The owning document
- * \param type The type of node to create
- * \param name The node name, or NULL
- * \param value The node value, or NULL
- * \param result Pointer to location to receive created node
- * \return DOM_NO_ERR on success, appropriate error otherwise
- *
- * ::doc, ::name and ::value will have their reference counts increased.
- *
- * The created node will already be referenced.
- */
-dom_exception dom_characterdata_create(struct dom_document *doc,
- dom_node_type type, struct dom_string *name,
- struct dom_string *value, struct dom_characterdata **result)
-{
- struct dom_characterdata *cdata;
- dom_exception err;
-
- /* Allocate object */
- cdata = dom_document_alloc(doc, NULL,
- sizeof(struct dom_characterdata));
- if (cdata == NULL)
- return DOM_NO_MEM_ERR;
-
- /* Initialise node contents */
- err = dom_characterdata_initialise(cdata, doc, type, name, value);
- if (err != DOM_NO_ERR) {
- dom_document_alloc(doc, cdata, 0);
- return err;
- }
-
- *result = cdata;
-
- return DOM_NO_ERR;
-}
-
-/**
* Initialise a character data node
*
* \param node The node to initialise
diff --git a/src/core/characterdata.h b/src/core/characterdata.h
index cde3969..6a2b329 100644
--- a/src/core/characterdata.h
+++ b/src/core/characterdata.h
@@ -17,10 +17,6 @@ struct dom_characterdata {
struct dom_node base; /**< Base node */
};
-dom_exception dom_characterdata_create(struct dom_document *doc,
- dom_node_type type, struct dom_string *name,
- struct dom_string *value, struct dom_characterdata **result);
-
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);
diff --git a/src/core/comment.c b/src/core/comment.c
new file mode 100644
index 0000000..e29edda
--- /dev/null
+++ b/src/core/comment.c
@@ -0,0 +1,56 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "core/characterdata.h"
+#include "core/comment.h"
+#include "core/document.h"
+
+/**
+ * A DOM comment node
+ */
+struct dom_comment {
+ struct dom_characterdata base; /**< Base node */
+};
+
+/**
+ * Create a comment node
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_comment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_comment **result)
+{
+ struct dom_comment *c;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ c = dom_document_alloc(doc, NULL, sizeof(struct dom_comment));
+ if (c == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_characterdata_initialise(&c->base, doc, DOM_COMMENT_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, c, 0);
+ return err;
+ }
+
+ *result = c;
+
+ return DOM_NO_ERR;
+}
diff --git a/src/core/comment.h b/src/core/comment.h
new file mode 100644
index 0000000..1cc7d28
--- /dev/null
+++ b/src/core/comment.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_comment_h_
+#define dom_internal_core_comment_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_comment;
+struct dom_document;
+struct dom_string;
+
+dom_exception dom_comment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_comment **result);
+
+#endif
diff --git a/src/core/doc_fragment.c b/src/core/doc_fragment.c
new file mode 100644
index 0000000..0792467
--- /dev/null
+++ b/src/core/doc_fragment.c
@@ -0,0 +1,57 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "core/document.h"
+#include "core/doc_fragment.h"
+#include "core/node.h"
+
+/**
+ * A DOM document fragment
+ */
+struct dom_document_fragment {
+ struct dom_node base; /**< Base node */
+};
+
+/**
+ * Create a document fragment
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_document_fragment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_document_fragment **result)
+{
+ struct dom_document_fragment *f;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ f = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_document_fragment));
+ if (f == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_node_initialise(&f->base, doc, DOM_DOCUMENT_FRAGMENT_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, f, 0);
+ return err;
+ }
+
+ *result = f;
+
+ return DOM_NO_ERR;
+}
diff --git a/src/core/doc_fragment.h b/src/core/doc_fragment.h
new file mode 100644
index 0000000..9e27811
--- /dev/null
+++ b/src/core/doc_fragment.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_documentfragment_h_
+#define dom_internal_core_documentfragment_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document_fragment;
+struct dom_document;
+struct dom_string;
+
+dom_exception dom_document_fragment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_document_fragment **result);
+
+#endif
diff --git a/src/core/document.c b/src/core/document.c
index b5a712e..cc38c3e 100644
--- a/src/core/document.c
+++ b/src/core/document.c
@@ -10,12 +10,17 @@
#include <dom/core/document.h>
#include "core/attr.h"
+#include "core/cdatasection.h"
#include "core/characterdata.h"
+#include "core/comment.h"
#include "core/document.h"
+#include "core/doc_fragment.h"
#include "core/element.h"
+#include "core/entity_ref.h"
#include "core/namednodemap.h"
#include "core/node.h"
#include "core/nodelist.h"
+#include "core/pi.h"
#include "core/text.h"
#include "utils/utils.h"
@@ -161,9 +166,9 @@ dom_exception dom_document_create_element(struct dom_document *doc,
* finished with it.
*/
dom_exception dom_document_create_document_fragment(struct dom_document *doc,
- struct dom_node **result)
+ struct dom_document_fragment **result)
{
- return dom_node_create(doc, DOM_DOCUMENT_FRAGMENT_NODE,
+ return dom_document_fragment_create(doc,
doc->nodenames[DOM_DOCUMENT_FRAGMENT_NODE],
NULL, result);
}
@@ -183,8 +188,8 @@ dom_exception dom_document_create_document_fragment(struct dom_document *doc,
dom_exception dom_document_create_text_node(struct dom_document *doc,
struct dom_string *data, struct dom_text **result)
{
- return dom_text_create(doc, DOM_TEXT_NODE,
- doc->nodenames[DOM_TEXT_NODE], data, result);
+ return dom_text_create(doc, doc->nodenames[DOM_TEXT_NODE],
+ data, result);
}
/**
@@ -200,10 +205,10 @@ dom_exception dom_document_create_text_node(struct dom_document *doc,
* finished with it.
*/
dom_exception dom_document_create_comment(struct dom_document *doc,
- struct dom_string *data, struct dom_characterdata **result)
+ struct dom_string *data, struct dom_comment **result)
{
- return dom_characterdata_create(doc, DOM_COMMENT_NODE,
- doc->nodenames[DOM_COMMENT_NODE], data, result);
+ return dom_comment_create(doc, doc->nodenames[DOM_COMMENT_NODE],
+ data, result);
}
/**
@@ -220,9 +225,9 @@ dom_exception dom_document_create_comment(struct dom_document *doc,
* finished with it.
*/
dom_exception dom_document_create_cdata_section(struct dom_document *doc,
- struct dom_string *data, struct dom_text **result)
+ struct dom_string *data, struct dom_cdata_section **result)
{
- return dom_text_create(doc, DOM_CDATA_SECTION_NODE,
+ return dom_cdata_section_create(doc,
doc->nodenames[DOM_CDATA_SECTION_NODE],
data, result);
}
@@ -245,12 +250,11 @@ dom_exception dom_document_create_cdata_section(struct dom_document *doc,
dom_exception dom_document_create_processing_instruction(
struct dom_document *doc, struct dom_string *target,
struct dom_string *data,
- struct dom_node **result)
+ struct dom_processing_instruction **result)
{
/** \todo is the use of target as the node name correct? */
- return dom_node_create(doc, DOM_PROCESSING_INSTRUCTION_NODE,
- target, data, result);
+ return dom_processing_instruction_create(doc, target, data, result);
}
/**
@@ -287,10 +291,10 @@ dom_exception dom_document_create_attribute(struct dom_document *doc,
* finished with it.
*/
dom_exception dom_document_create_entity_reference(struct dom_document *doc,
- struct dom_string *name, struct dom_node **result)
+ struct dom_string *name,
+ struct dom_entity_reference **result)
{
- return dom_node_create(doc, DOM_ENTITY_REFERENCE_NODE,
- name, NULL, result);
+ return dom_entity_reference_create(doc, name, NULL, result);
}
/**
diff --git a/src/core/entity_ref.c b/src/core/entity_ref.c
new file mode 100644
index 0000000..7bc103e
--- /dev/null
+++ b/src/core/entity_ref.c
@@ -0,0 +1,57 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "core/document.h"
+#include "core/entity_ref.h"
+#include "core/node.h"
+
+/**
+ * A DOM entity reference
+ */
+struct dom_entity_reference {
+ struct dom_node base; /**< Base node */
+};
+
+/**
+ * Create an entity reference
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_entity_reference_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_entity_reference **result)
+{
+ struct dom_entity_reference *e;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ e = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_entity_reference));
+ if (e == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_node_initialise(&e->base, doc, DOM_ENTITY_REFERENCE_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, e, 0);
+ return err;
+ }
+
+ *result = e;
+
+ return DOM_NO_ERR;
+}
diff --git a/src/core/entity_ref.h b/src/core/entity_ref.h
new file mode 100644
index 0000000..b1f9dff
--- /dev/null
+++ b/src/core/entity_ref.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_entityreference_h_
+#define dom_internal_core_entityreference_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document;
+struct dom_entity_reference;
+struct dom_string;
+
+dom_exception dom_entity_reference_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_entity_reference **result);
+
+#endif
diff --git a/src/core/node.c b/src/core/node.c
index 4f15617..04a1230 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -13,65 +13,6 @@
#include "utils/utils.h"
/**
- * Create a DOM node of the given type
- *
- * \param doc The owning document
- * \param type The type of node to create
- * \param name The node name, or NULL
- * \param value The node value, or NULL
- * \param result Pointer to location to receive created node
- * \return DOM_NO_ERR on success, appropriate error otherwise
- *
- * ::doc, ::name and ::value will have their reference counts increased.
- *
- * The created node will already be referenced.
- */
-dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
- struct dom_string *name, struct dom_string *value,
- struct dom_node **result)
-{
- struct dom_node *node;
- dom_exception err;
-
- /* If there's a type-specific constructor, use that */
- switch (type) {
- case DOM_ELEMENT_NODE:
- return dom_document_create_element(doc, name,
- (struct dom_element **) result);
- case DOM_ATTRIBUTE_NODE:
- return dom_document_create_attribute(doc, name,
- (struct dom_attr **) result);
- case DOM_TEXT_NODE:
- return dom_document_create_text_node(doc, value,
- (struct dom_text **) result);
- case DOM_CDATA_SECTION_NODE:
- return dom_document_create_cdata_section(doc, value,
- (struct dom_text **) result);
- case DOM_COMMENT_NODE:
- return dom_document_create_comment(doc, value,
- (struct dom_characterdata **) result);
- default:
- break;
- }
-
- /* Otherwise, this is a generic node, so build it ourselves */
- node = dom_document_alloc(doc, NULL, sizeof(struct dom_node));
- if (node == NULL)
- return DOM_NO_MEM_ERR;
-
- /* Initialise node contents */
- err = dom_node_initialise(node, doc, type, name, value);
- if (err != DOM_NO_ERR) {
- dom_document_alloc(doc, node, 0);
- return err;
- }
-
- *result = node;
-
- return DOM_NO_ERR;
-}
-
-/**
* Initialise a DOM node
*
* \param node The node to initialise
diff --git a/src/core/node.h b/src/core/node.h
index 6a72efd..168d2ec 100644
--- a/src/core/node.h
+++ b/src/core/node.h
@@ -52,10 +52,6 @@ struct dom_node {
uint32_t refcnt; /**< Reference count */
};
-dom_exception dom_node_create(struct dom_document *doc, dom_node_type type,
- struct dom_string *name, struct dom_string *value,
- struct dom_node **result);
-
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);
diff --git a/src/core/pi.c b/src/core/pi.c
new file mode 100644
index 0000000..55e85f7
--- /dev/null
+++ b/src/core/pi.c
@@ -0,0 +1,58 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "core/document.h"
+#include "core/node.h"
+#include "core/pi.h"
+
+/**
+ * A DOM processing instruction
+ */
+struct dom_processing_instruction {
+ struct dom_node base; /**< Base node */
+};
+
+/**
+ * Create a processing instruction
+ *
+ * \param doc The owning document
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \param result Pointer to location to receive created node
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_processing_instruction_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_processing_instruction **result)
+{
+ struct dom_processing_instruction *p;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ p = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_processing_instruction));
+ if (p == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_node_initialise(&p->base, doc,
+ DOM_PROCESSING_INSTRUCTION_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, p, 0);
+ return err;
+ }
+
+ *result = p;
+
+ return DOM_NO_ERR;
+}
diff --git a/src/core/pi.h b/src/core/pi.h
new file mode 100644
index 0000000..1d7560f
--- /dev/null
+++ b/src/core/pi.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_processinginstruction_h_
+#define dom_internal_core_processinginstruction_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_document;
+struct dom_processing_instruction;
+struct dom_string;
+
+dom_exception dom_processing_instruction_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_processing_instruction **result);
+
+#endif
diff --git a/src/core/text.c b/src/core/text.c
index 5c2308a..05e2b7d 100644
--- a/src/core/text.c
+++ b/src/core/text.c
@@ -14,20 +14,9 @@
#include "utils/utils.h"
/**
- * A DOM text node
- */
-struct dom_text {
- struct dom_characterdata base; /**< Base node */
-
- bool element_content_whitespace; /**< This node is element
- * content whitespace */
-};
-
-/**
* Create a text node
*
* \param doc The owning document
- * \param type The type of text node to create
* \param name The name of the node to create
* \param value The text content of the node
* \param result Pointer to location to receive created node
@@ -38,34 +27,61 @@ struct dom_text {
*
* The returned node will already be referenced.
*/
-dom_exception dom_text_create(struct dom_document *doc, dom_node_type type,
+dom_exception dom_text_create(struct dom_document *doc,
struct dom_string *name, struct dom_string *value,
struct dom_text **result)
{
struct dom_text *t;
dom_exception err;
- /* Allocate the element */
+ /* Allocate the text node */
t = dom_document_alloc(doc, NULL, sizeof(struct dom_text));
if (t == NULL)
return DOM_NO_MEM_ERR;
- /* Initialise the base class */
- err = dom_characterdata_initialise(&t->base, doc, type, name, value);
+ /* And initialise the node */
+ err = dom_text_initialise(t, doc, DOM_TEXT_NODE, name, value);
if (err != DOM_NO_ERR) {
dom_document_alloc(doc, t, 0);
return err;
}
- /* Perform our type-specific initialisation */
- t->element_content_whitespace = false;
-
*result = t;
return DOM_NO_ERR;
}
/**
+ * Initialise a text node
+ *
+ * \param text The node to initialise
+ * \param doc The owning document
+ * \param type The type of the node
+ * \param name The name of the node to create
+ * \param value The text content of the node
+ * \return DOM_NO_ERR on success.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ */
+dom_exception dom_text_initialise(struct dom_text *text,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value)
+{
+ dom_exception err;
+
+ /* Initialise the base class */
+ err = dom_characterdata_initialise(&text->base, doc, type,
+ name, value);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ /* Perform our type-specific initialisation */
+ text->element_content_whitespace = false;
+
+ return DOM_NO_ERR;
+}
+
+/**
* Split a text node at a given character offset
*
* \param text The node to split
diff --git a/src/core/text.h b/src/core/text.h
index 97ab900..be927df 100644
--- a/src/core/text.h
+++ b/src/core/text.h
@@ -8,16 +8,31 @@
#ifndef dom_internal_core_text_h_
#define dom_internal_core_text_h_
+#include <stdbool.h>
+
#include <dom/core/exceptions.h>
-#include "core/node.h"
+#include "core/characterdata.h"
struct dom_document;
struct dom_string;
-struct dom_text;
-dom_exception dom_text_create(struct dom_document *doc, dom_node_type type,
+/**
+ * A DOM text node
+ */
+struct dom_text {
+ struct dom_characterdata base; /**< Base node */
+
+ bool element_content_whitespace; /**< This node is element
+ * content whitespace */
+};
+
+dom_exception dom_text_create(struct dom_document *doc,
struct dom_string *name, struct dom_string *value,
struct dom_text **result);
+dom_exception dom_text_initialise(struct dom_text *text,
+ struct dom_document *doc, dom_node_type type,
+ struct dom_string *name, struct dom_string *value);
+
#endif