From 152e52676552a2a7eeb38f679c8b74d2e6251b2c Mon Sep 17 00:00:00 2001 From: Richard Schwarting Date: Sun, 28 Jul 2013 01:30:11 -0400 Subject: [PATCH] examples/c: add document_factory.c, remove a comment from document_properties.c --- examples/c/Makefile.example | 2 +- examples/c/document_factory.c | 52 ++++++++++++++++++++++++++++++++ examples/c/document_properties.c | 1 - 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 examples/c/document_factory.c diff --git a/examples/c/Makefile.example b/examples/c/Makefile.example index a0293a84..664c4ef0 100644 --- a/examples/c/Makefile.example +++ b/examples/c/Makefile.example @@ -1,7 +1,7 @@ CC=gcc CFLAGS=`pkg-config --cflags gxml gio-2.0` -g -Wall LDFLAGS=`pkg-config --libs gxml gio-2.0` -PROGS=create_document create_document_minimal create_document_from_string create_document_from_file create_document_from_path save_document_to_path save_document_to_stream +PROGS=document_create document_create_minimal document_create_from_string document_create_from_file document_create_from_path document_save_to_path document_save_to_stream document_properties document_factory all: $(PROGS) diff --git a/examples/c/document_factory.c b/examples/c/document_factory.c new file mode 100644 index 00000000..ff3869ee --- /dev/null +++ b/examples/c/document_factory.c @@ -0,0 +1,52 @@ +#include + +int main () { + GXmlDocument *doc; + + doc = gxml_document_new (); + + /* */ + GXmlElement *elem; + elem = gxml_document_create_element (doc, "tagname"); + + GXmlDocumentFragment *docfragment; + docfragment = gxml_document_create_document_fragment (doc); + + /* Between the book tags is text! */ + GXmlText *text; + text = gxml_document_create_text_node (doc, "Here is some text in an XML document"); + + /* The fault in our stars */ + GXmlComment *comment; + comment = gxml_document_create_comment (doc, "Here is an XML comment"); + + /* */ + GXmlCDATASection *cdata; + cdata = gxml_document_create_cdata_section (doc, "non-XML data like code or special entities"); + + /* */ + GXmlProcessingInstruction *pi; + pi = gxml_document_create_processing_instruction (doc, "xml", "href=\"style.xsl\" type=\"text/xml\""); + + /* */ + GXmlAttr *attr; + attr = gxml_document_create_attribute (doc, "id"); + + /* ' (for an apostrophe, ') */ + GXmlEntityReference *entref; + entref = gxml_document_create_entity_reference (doc, "apos"); + + gxml_node_append_child (GXML_NODE (doc), GXML_NODE (elem)); + + g_object_unref (elem); + g_object_unref (pi); + g_object_unref (entref); + g_object_unref (attr); + g_object_unref (docfragment); + g_object_unref (text); + g_object_unref (comment); + g_object_unref (cdata); + g_object_unref (doc); + + return 0; +} diff --git a/examples/c/document_properties.c b/examples/c/document_properties.c index 60033343..da3ee18a 100644 --- a/examples/c/document_properties.c +++ b/examples/c/document_properties.c @@ -8,7 +8,6 @@ int main () { xml = ""; doc = gxml_document_new_from_string (xml); - // should be "#document" const gchar *doc_node_name; doc_node_name = gxml_node_get_node_name (GXML_NODE (doc)); printf ("A document's node_name is: %s (which should always be '#document')\n\n", doc_node_name); -- GitLab