[gxml] examples/js: rename several examples, add new ones
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] examples/js: rename several examples, add new ones
- Date: Fri, 23 Aug 2013 20:59:52 +0000 (UTC)
commit d4c68d4e954489c0a540b175d7e5015c9bbbd881
Author: Richard Schwarting <aquarichy gmail com>
Date: Sun Jul 28 01:30:12 2013 -0400
examples/js: rename several examples, add new ones
examples/js/document_factory.js | 36 ++++++++++++++++++++++++++++++++++++
examples/js/document_properties.js | 19 +++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/examples/js/document_factory.js b/examples/js/document_factory.js
new file mode 100755
index 0000000..49a62f2
--- /dev/null
+++ b/examples/js/document_factory.js
@@ -0,0 +1,36 @@
+#!/usr/bin/gjs
+
+const GXml = imports.gi.GXml;
+
+let doc = GXml.Document.new ();
+
+/* <book></book> */
+let elem = doc.create_element ("book");
+print ("Book element: " + elem.to_string (false, 0));
+
+let docfragment = doc.create_document_fragment ();
+print ("Fragment: " + docfragment.to_string (false, 0));
+
+/* <book>Between the book tags is text!</book> */
+let text = doc.create_text_node ("Between the book tags is text!");
+print ("Text: " + text.to_string (false, 0));
+
+/* <book><!-- comment: I really like this book -->The fault in our stars</book> */
+let comment = doc.create_comment ("comment: I really like this book");
+print ("Comment: " + comment.to_string (false, 0));
+
+/* <![CDATA[non-XML data like code or special entities]]> */
+let cdata = doc.create_cdata_section ("non-XML data like code or special entities");
+print ("CDATA section: " + cdata.to_string (false, 0));
+
+/* <?xml href="style.xsl" type="text/xml"?> */
+let pi = doc.create_processing_instruction ("xml", "href=\"style.xsl\" type=\"text/xml\"");
+print ("Processing Instruction: " + pi.to_string (false, 0));
+
+/* <element id=""> */
+let attr = doc.create_attribute ("id");
+print ("Attribute: " + attr.to_string (false, 0));
+
+/* ' (for an apostrophe, ') */
+let entref = doc.create_entity_reference ("apos");
+print ("Entity reference: " + entref.to_string (false, 0));
diff --git a/examples/js/document_properties.js b/examples/js/document_properties.js
new file mode 100755
index 0000000..b154fc9
--- /dev/null
+++ b/examples/js/document_properties.js
@@ -0,0 +1,19 @@
+#!/usr/bin/gjs
+
+const GXml = imports.gi.GXml;
+
+let 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 & Prejudice\"/><Book author=\"J.D. Salinger\" title=\"Nine Stories\"/></Books></Bookshelf>";
+let doc = GXml.Document.from_string (xml);
+
+print ("A document's node_name is: " + doc.node_name + " (which should always be '#document')\n");
+
+print ("The document's doctype is: " + doc.doctype.name + " (which should be 'bookshelf')\n");
+
+let impl = doc.implementation;
+print ("GXml's implementation that created this document has the features\n xml 1.0? " +
+ (impl.has_feature ("xml", "1.0") ? "true" : "false") +
+ " (should be true)\n html? " +
+ (impl.has_feature ("html", null) ? "true" : "false") +
+ " (should be false)\n");
+
+print ("Document has root element with name: " + doc.document_element.node_name + " (should be
'Bookshelf')");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]