[gxml/gsoc2013] examples/c: add Document properties example; rename examples



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

    examples/c: add Document properties example; rename examples

 .../c/{create_document.c => document_create.c}     |    0
 ...ent_from_file.c => document_create_from_file.c} |    0
 ...ent_from_path.c => document_create_from_path.c} |    0
 ...from_string.c => document_create_from_string.c} |    0
 ...ocument_minimal.c => document_create_minimal.c} |    0
 examples/c/document_properties.c                   |   38 ++++++++++++++++++++
 ..._document_to_path.c => document_save_to_path.c} |    0
 ...ument_to_stream.c => document_save_to_stream.c} |    0
 8 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/examples/c/create_document.c b/examples/c/document_create.c
similarity index 100%
rename from examples/c/create_document.c
rename to examples/c/document_create.c
diff --git a/examples/c/create_document_from_file.c b/examples/c/document_create_from_file.c
similarity index 100%
rename from examples/c/create_document_from_file.c
rename to examples/c/document_create_from_file.c
diff --git a/examples/c/create_document_from_path.c b/examples/c/document_create_from_path.c
similarity index 100%
rename from examples/c/create_document_from_path.c
rename to examples/c/document_create_from_path.c
diff --git a/examples/c/create_document_from_string.c b/examples/c/document_create_from_string.c
similarity index 100%
rename from examples/c/create_document_from_string.c
rename to examples/c/document_create_from_string.c
diff --git a/examples/c/create_document_minimal.c b/examples/c/document_create_minimal.c
similarity index 100%
rename from examples/c/create_document_minimal.c
rename to examples/c/document_create_minimal.c
diff --git a/examples/c/document_properties.c b/examples/c/document_properties.c
new file mode 100644
index 0000000..6003334
--- /dev/null
+++ b/examples/c/document_properties.c
@@ -0,0 +1,38 @@
+#include <gxml/gxml.h>
+#include <stdio.h>
+
+int main () {
+  char *xml;
+  GXmlDocument *doc;
+
+  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);
+
+  GXmlDocumentType *doctype; // TODO: have renamed to GXmlDocType
+  const gchar *doctype_name; // we don't want to have to free this
+
+  doctype = gxml_document_get_doctype (doc);
+  doctype_name = gxml_document_type_get_name (doctype);
+  printf ("The document's doctype is: %s (which should be 'bookshelf')\n\n", doctype_name);
+
+  GXmlImplementation *impl;
+  impl = gxml_document_get_implementation (doc);
+
+  printf ("GXml's implementation that created this document has the features\n  xml 1.0? %s (should be 
true)\n  html? %s (should be false)\n\n", gxml_implementation_has_feature (impl, "xml", "1.0") ? "true" : 
"false", gxml_implementation_has_feature (impl, "html", NULL) ? "true" : "false");
+
+  GXmlElement *root;
+  const gchar *root_node_name;
+  root = gxml_document_get_document_element (doc);
+  root_node_name = gxml_node_get_node_name (GXML_NODE (root));
+
+  printf ("Document has root element with name: %s (should be Bookshelf)\n", root_node_name);  
+
+  g_object_unref (doc);
+
+  return 0;
+}
diff --git a/examples/c/save_document_to_path.c b/examples/c/document_save_to_path.c
similarity index 100%
rename from examples/c/save_document_to_path.c
rename to examples/c/document_save_to_path.c
diff --git a/examples/c/save_document_to_stream.c b/examples/c/document_save_to_stream.c
similarity index 100%
rename from examples/c/save_document_to_stream.c
rename to examples/c/document_save_to_stream.c


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