[gxml/gsoc2013] examples/c: rename examples



commit d1d13211b440fc6279884c3328e4e983ee46ddfc
Author: Richard Schwarting <aquarichy gmail com>
Date:   Tue Aug 20 16:20:42 2013 -0400

    examples/c: rename examples

 examples/c/document_create.c                       |   92 +++++++++----------
 examples/c/document_factory.c                      |   55 ------------
 .../{document_create_minimal.c => document_new.c}  |   16 ++--
 ...create_from_file.c => document_new_from_file.c} |    0
 ...create_from_path.c => document_new_from_path.c} |    0
 ...te_from_string.c => document_new_from_string.c} |    0
 ...ent_create_minimal.c => document_new_minimal.c} |    0
 7 files changed, 54 insertions(+), 109 deletions(-)
---
diff --git a/examples/c/document_create.c b/examples/c/document_create.c
index 0727af4..b5c1f60 100644
--- a/examples/c/document_create.c
+++ b/examples/c/document_create.c
@@ -1,59 +1,55 @@
 #include <gxml/gxml.h>
-#include <stdio.h>
 
 int main () {
   GXmlDocument *doc;
-  GXmlElement *root;
-  GXmlElement *owner;
-  GXmlElement *books;
-  GXmlElement *book;
-  int i;
-  char *str;
-
-  char *authors[] = { "John Green", "Jane Austen", "J.D. Salinger" };
-  char *titles[] = { "The Fault in Our Stars", "Pride & Prejudice", "Nine Stories" };
 
   doc = gxml_document_new ();
 
-  // Add a root node
-  root = gxml_document_create_element (doc, "Bookshelf");
-
-  gxml_node_append_child (GXML_NODE (doc), GXML_NODE (root));
-  // if we tried to add a second one, it would fail :), and a g_warning would be printed
-
-  // Add an owner node
-  owner = gxml_document_create_element (doc, "Owner");
-  gxml_node_append_child (GXML_NODE (root), GXML_NODE (owner));
-  gxml_element_set_attribute (owner, "fullname", "John Green");
-  // TODO: need to figure out what sort of errors these would return,
-  // want the devhelp pages to describe meaningful possible errors
-
-  // Add a collection of books
-  books = gxml_document_create_element (doc, "Books");
-  gxml_node_append_child (GXML_NODE (root), GXML_NODE (books));
-
-  for (i = 0; i < sizeof (authors) / sizeof (char*); i++) {
-    book = gxml_document_create_element (doc, "Book");
-    gxml_element_set_attribute (book, "author", authors[i]);
-    gxml_element_set_attribute (book, "title", titles[i]);
-    gxml_node_append_child (GXML_NODE (books), GXML_NODE (book));
-  }
-
-  // TODO: want a "gxml_node_from_string ()"; make sure document ownership transfer properly
-
-  str = gxml_node_to_string (GXML_NODE (doc), TRUE, 2);
-  printf ("%s:\n%s\n", __FILE__, str);
-  g_free (str);
-
+  /* <bookElement></bookElement> */
+  GXmlElement *elem;
+  elem = gxml_document_create_element (doc, "bookElement");
+  printf ("Book element: %s\n", gxml_node_to_string (GXML_NODE (elem), FALSE, 0));
+
+  GXmlDocumentFragment *docfragment;
+  docfragment = gxml_document_create_document_fragment (doc);
+  printf ("Document fragment: %s\n", gxml_node_to_string (GXML_NODE (docfragment), FALSE, 0));
+
+  /* <book>Between the book tags is text!</book> */
+  GXmlText *text;
+  text = gxml_document_create_text_node (doc, "Between the book tags is text!");
+  printf ("Text node: %s\n", gxml_node_to_string (GXML_NODE (text), FALSE, 0));
+
+  /* <book><!-- comment: I really like this book -->The fault in our stars</book> */
+  GXmlComment *comment;
+  comment = gxml_document_create_comment (doc, "comment: I really like this book");
+  printf ("Comment: %s\n", gxml_node_to_string (GXML_NODE (comment), FALSE, 0));
+
+  /* <![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");
+  printf ("CDATA section: %s\n", gxml_node_to_string (GXML_NODE (cdata), FALSE, 0));
+
+  /* <?xml href="style.xsl" type="text/xml"?> */
+  GXmlProcessingInstruction *pi;
+  pi = gxml_document_create_processing_instruction (doc, "xml", "href=\"style.xsl\" type=\"text/xml\"");
+  printf ("Processing Instruction: %s\n", gxml_node_to_string (GXML_NODE (pi), FALSE, 0));
+
+  /* <element id=""> */
+  GXmlAttr *attr;
+  attr = gxml_document_create_attribute (doc, "id");
+  printf ("Attribute: %s\n", gxml_node_to_string (GXML_NODE (attr), FALSE, 0));
+
+  /* &apos;   (for an apostrophe, ') */
+  GXmlEntityReference *entref;
+  entref = gxml_document_create_entity_reference (doc, "apos");
+  printf ("Entity reference: %s\n", gxml_node_to_string (GXML_NODE (entref), FALSE, 0));
+
+  gxml_node_append_child (GXML_NODE (doc), GXML_NODE (elem));
+
+  g_object_unref (pi);
+  g_object_unref (entref);
+  g_object_unref (attr);
   g_object_unref (doc);
-  g_object_unref (root); // TODO: figure out what happens to root if you deallocate doc?! */
-  // TODO: perhaps see whether we can make it that all the nodes that are returned are weak references
-  g_object_unref (owner);
-  g_object_unref (books);
-  g_object_unref (book);
-  /* In util/ there's a small programme that tells you when ownership
-     is transfered (that is, you are given a return value that you own
-     and must free. */
 
   return 0;
 }
diff --git a/examples/c/document_create_minimal.c b/examples/c/document_new.c
similarity index 74%
copy from examples/c/document_create_minimal.c
copy to examples/c/document_new.c
index b418320..0727af4 100644
--- a/examples/c/document_create_minimal.c
+++ b/examples/c/document_new.c
@@ -1,7 +1,6 @@
 #include <gxml/gxml.h>
 #include <stdio.h>
 
-
 int main () {
   GXmlDocument *doc;
   GXmlElement *root;
@@ -18,8 +17,9 @@ int main () {
 
   // Add a root node
   root = gxml_document_create_element (doc, "Bookshelf");
+
   gxml_node_append_child (GXML_NODE (doc), GXML_NODE (root));
-  // if we tried to add a second one, it would fail and a g_warning would be printed :)
+  // if we tried to add a second one, it would fail :), and a g_warning would be printed
 
   // Add an owner node
   owner = gxml_document_create_element (doc, "Owner");
@@ -31,6 +31,7 @@ int main () {
   // Add a collection of books
   books = gxml_document_create_element (doc, "Books");
   gxml_node_append_child (GXML_NODE (root), GXML_NODE (books));
+
   for (i = 0; i < sizeof (authors) / sizeof (char*); i++) {
     book = gxml_document_create_element (doc, "Book");
     gxml_element_set_attribute (book, "author", authors[i]);
@@ -38,18 +39,21 @@ int main () {
     gxml_node_append_child (GXML_NODE (books), GXML_NODE (book));
   }
 
+  // TODO: want a "gxml_node_from_string ()"; make sure document ownership transfer properly
+
   str = gxml_node_to_string (GXML_NODE (doc), TRUE, 2);
   printf ("%s:\n%s\n", __FILE__, str);
   g_free (str);
 
   g_object_unref (doc);
-  g_object_unref (root);
+  g_object_unref (root); // TODO: figure out what happens to root if you deallocate doc?! */
+  // TODO: perhaps see whether we can make it that all the nodes that are returned are weak references
   g_object_unref (owner);
   g_object_unref (books);
   g_object_unref (book);
-
-  // TODO: how do we clean them up?
+  /* In util/ there's a small programme that tells you when ownership
+     is transfered (that is, you are given a return value that you own
+     and must free. */
 
   return 0;
 }
-
diff --git a/examples/c/document_create_from_file.c b/examples/c/document_new_from_file.c
similarity index 100%
rename from examples/c/document_create_from_file.c
rename to examples/c/document_new_from_file.c
diff --git a/examples/c/document_create_from_path.c b/examples/c/document_new_from_path.c
similarity index 100%
rename from examples/c/document_create_from_path.c
rename to examples/c/document_new_from_path.c
diff --git a/examples/c/document_create_from_string.c b/examples/c/document_new_from_string.c
similarity index 100%
rename from examples/c/document_create_from_string.c
rename to examples/c/document_new_from_string.c
diff --git a/examples/c/document_create_minimal.c b/examples/c/document_new_minimal.c
similarity index 100%
rename from examples/c/document_create_minimal.c
rename to examples/c/document_new_minimal.c


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