[gxml/gsoc2013] examples/c: add document_factory.c, remove a comment from document_properties.c



commit bca62f6ca49f6454fed1e881eaf64e930c7af29e
Author: Richard Schwarting <aquarichy gmail com>
Date:   Sun Jul 28 01:30:11 2013 -0400

    examples/c: add document_factory.c, remove a comment from document_properties.c

 examples/c/Makefile              |    2 +-
 examples/c/document_factory.c    |   52 ++++++++++++++++++++++++++++++++++++++
 examples/c/document_properties.c |    1 -
 3 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/examples/c/Makefile b/examples/c/Makefile
index a0293a8..664c4ef 100644
--- a/examples/c/Makefile
+++ b/examples/c/Makefile
@@ -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 0000000..ff3869e
--- /dev/null
+++ b/examples/c/document_factory.c
@@ -0,0 +1,52 @@
+#include <gxml/gxml.h>
+
+int main () {
+  GXmlDocument *doc;
+
+  doc = gxml_document_new ();
+
+  /* <bookElement> */
+  GXmlElement *elem;
+  elem = gxml_document_create_element (doc, "tagname");
+
+  GXmlDocumentFragment *docfragment;
+  docfragment = gxml_document_create_document_fragment (doc);
+
+  /* <book>Between the book tags is text!</book> */
+  GXmlText *text;
+  text = gxml_document_create_text_node (doc, "Here is some text in an XML document");
+
+  /* <book><!-- comment: I really like this one -->The fault in our stars</book> */
+  GXmlComment *comment;
+  comment = gxml_document_create_comment (doc, "Here is an XML comment");
+
+  /* <![CDATA[non-XML data like code or special entities]]> */
+  GXmlCDATASection *cdata;
+  cdata = gxml_document_create_cdata_section (doc, "non-XML data like code or special entities");
+
+  /* <?xml href="style.xsl" type="text/xml"?> */
+  GXmlProcessingInstruction *pi;
+  pi = gxml_document_create_processing_instruction (doc, "xml", "href=\"style.xsl\" type=\"text/xml\"");
+
+  /* <element id=""> */
+  GXmlAttr *attr;
+  attr = gxml_document_create_attribute (doc, "id");
+
+  /* &apos;   (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 6003334..da3ee18 100644
--- a/examples/c/document_properties.c
+++ b/examples/c/document_properties.c
@@ -8,7 +8,6 @@ int main () {
   xml = "<?xml version=\"1.0\"?><!DOCTYPE bookshelf><Bookshelf><Owner fullname=\"John Green\"/><Books><Book 
author=\"John Green\" title=\"The Fault in Our Stars\"/><Book author=\"Jane Austen\" title=\"Pride &amp; 
Prejudice\"/><Book author=\"J.D. Salinger\" title=\"Nine Stories\"/></Books></Bookshelf>";
   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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]