[gxml] Fix GomNode.replace_child(). Ported JS examples



commit 50391684330e72ae312786f527c59bbf2a7f66c8
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Sep 6 16:13:40 2017 -0700

    Fix GomNode.replace_child(). Ported JS examples

 examples/js/attr.js                     |    1 -
 examples/js/cdata_section.js            |    8 ----
 examples/js/character_data.js           |   24 ++++++------
 examples/js/comment.js                  |   21 +++++------
 examples/js/document_create.js          |   25 ++++---------
 examples/js/document_new.js             |   30 ++++++++--------
 examples/js/document_new_from_file.js   |    4 +-
 examples/js/document_new_from_path.js   |    4 +-
 examples/js/document_new_from_string.js |    4 +-
 examples/js/document_properties.js      |   10 +++--
 examples/js/document_save_to_path.js    |    6 ++-
 examples/js/element.js                  |   36 +++++++++---------
 examples/js/node_child_management.js    |   46 ++++++++++++------------
 examples/js/node_list.js                |   58 +++---------------------------
 examples/js/node_self.js                |   43 +++++++++-------------
 examples/js/text.js                     |   10 +++---
 gxml/GomNode.vala                       |    2 +-
 17 files changed, 131 insertions(+), 201 deletions(-)
---
diff --git a/examples/js/character_data.js b/examples/js/character_data.js
index ff09f9a..27de656 100755
--- a/examples/js/character_data.js
+++ b/examples/js/character_data.js
@@ -5,9 +5,9 @@ const GXml = imports.gi.GXml;
 print ("CharacterData isn't directly instantiable, but its subclasses Text and Comment are!\n");
 
 // Setup
-var doc = GXml.Document.from_path ("bookshelf_node.xml");
+var doc = GXml.GomDocument.from_path ("bookshelf_node.xml");
 var books_list = doc.document_element.get_elements_by_tag_name ("Book");
-var book = books_list.nth (0);
+var book = books_list.get_element (0);
 
 // Create a Text node for CharacterData
 var text = doc.create_text_node ("Some infinities are bigger than other infinities");
@@ -16,36 +16,36 @@ var comment = doc.create_comment ("As he read, I fell in love the way you fall a
 /* Data representation */
 
 print ("Stringifying Text:\n" +
-       text.to_string (true, 0) + "\n\n" +
+       text.data + "\n\n" +
        "Text's CharacterData's data:\n" +
        text.data + "\n\n" +
        "Text's CharacterData's length:\n" +
-       text.length + "\n\n" +
+       text.get_length () + "\n\n" +
        "Stringifying Comment:\n" +
-       comment.to_string (true, 0) + "\n\n" +
+       comment.data + "\n\n" +
        "Comment's CharacterData's data:\n" +
        comment.data + "\n\n" +
        "Comment's CharacterData's length:\n" +
-       comment.length + "\n\n");
+       comment.get_length () + "\n\n");
 
 /* CharacterData operations */
 
 book.append_child (text);
-print ("Book with our Text as its child (its content):\n" + book.to_string (true, 0));
+print ("Book with our Text as its child (its content):\n" + book.write_string ());
 
 book.replace_child (comment, text);
-print ("\nBook with our Comment as its child (its content):\n" + book.to_string (true, 0));
+print ("\nBook with our Comment as its child (its content):\n" + book.write_string ());
 
 comment.append_data (" slowly, and then all at once");
-print ("\nBook after appending more data to Comment:\n" + book.to_string (true, 0));
+print ("\nBook after appending more data to Comment:\n" + book.write_string ());
 
 comment.replace_data (3, 2, "Gus");
-print ("\nBook after replacing 'he' with 'Gus':\n" + book.to_string (true, 0));
+print ("\nBook after replacing 'he' with 'Gus':\n" + book.write_string ());
 
 comment.delete_data (20, 8);
-print ("\nBook after deleting 'in love ':\n" + book.to_string (true, 0));
+print ("\nBook after deleting 'in love ':\n" + book.write_string ());
 
 comment.insert_data (20, "in love ");
-print ("\nBook after inserting 'in love ':\n" + book.to_string (true, 0));
+print ("\nBook after inserting 'in love ':\n" + book.write_string ());
 
 /* You can see some more examples by looking at Comment and Text's examples */
diff --git a/examples/js/comment.js b/examples/js/comment.js
index b8ef43b..bf93435 100755
--- a/examples/js/comment.js
+++ b/examples/js/comment.js
@@ -3,52 +3,51 @@
 const GXml = imports.gi.GXml;
 
 /* Setup */
-var doc = GXml.Document.from_path ("bookshelf_node.xml");
+var doc = GXml.GomDocument.from_path ("bookshelf_node.xml");
 var bookshelf = doc.document_element;
 print ("Bookshelf, without any comments:\n" +
-       bookshelf.to_string (true, 0));
+       bookshelf.write_string ());
 
 /* Placing comments in the tree */
 
 var comment = doc.create_comment ("this bookshelf is small");
 doc.insert_before (comment, bookshelf);
 print ("\nAfter trying to insert a comment before our root element:\n" +
-       doc.to_string (true, 0));
+       doc.write_string ());
 
 comment = doc.create_comment ("its owner is an important author");
 var owner = bookshelf.first_child;
 bookshelf.insert_before (comment, owner);
 print ("\nAfter inserting a comment before our <owner>:\n" +
-       bookshelf.to_string (true, 0));
+       bookshelf.write_string ());
 
 comment = doc.create_comment ("I should buy more books");
 var books = owner.next_sibling;
 books.append_child (comment);
 print ("\nAfter appending a comment in <books>:\n" +
-       bookshelf.to_string (true, 0));
+       bookshelf.write_string ());
 
 var book = books.first_child;
 comment = doc.create_comment ("this pretty cool book will soon be a pretty cool movie");
 book.append_child (comment);
 print ("\nAfter adding a comment to an empty <book> node:\n" +
-       bookshelf.to_string (true, 0));
+       bookshelf.write_string ());
 
 /* Comments as CharacterData */
 
 print ("\nStringified Comments have <!-- -->, like this one:\n" +
-       comment.to_string (true, 0));
+       comment.data);
 
 print ("\nComments are CharacterData, so previous comment's data:\n" +
        comment.data);
        
 print ("\nComments are CharacterData, so previous comment's length:\n" +
-       comment.length);
+       comment.get_length ());
 
 comment.append_data (".  Did you read it?");
 print ("\nComment after using CharacterData's append_data ():\n" +
-       comment.to_string (true, 0));
+       comment.data);
 
 comment.replace_data (12, 4, "awesome");
 print ("\nComment after using CharacterData's replace_data () (cool -> awesome).\n" +
-       "Note that this affects the data as seen in CharacterData's .data property, excluding the comment's 
surrounding <!-- and -->:\n" +
-       comment.to_string (true, 0));
+       "Note that this affects the data as seen in CharacterData's .data property, excluding the comment's 
surrounding <!-- and -->:\n" +comment.data);
diff --git a/examples/js/document_create.js b/examples/js/document_create.js
index 49a62f2..d7c2148 100755
--- a/examples/js/document_create.js
+++ b/examples/js/document_create.js
@@ -2,35 +2,24 @@
 
 const GXml = imports.gi.GXml;
 
-let doc = GXml.Document.new ();
+let doc = GXml.GomDocument.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));
+print ("Book element: " + elem.write_string ());
 
 /* <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));
+print ("Text: " + text.data);
 
 /* <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));
+print ("Comment: " + comment.data);
 
 /* <?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));
+print ("Processing Instruction: " + pi.data);
 
 /* <element id=""> */
-let attr = doc.create_attribute ("id");
-print ("Attribute: " + attr.to_string (false, 0));
-
-/* &apos;   (for an apostrophe, ') */
-let entref = doc.create_entity_reference ("apos");
-print ("Entity reference: " + entref.to_string (false, 0));
+elem.set_attribute ("id", "001");
+print ("Attribute id: " + elem.get_attribute ("id"));
diff --git a/examples/js/document_new.js b/examples/js/document_new.js
index ee07b23..fab12d0 100755
--- a/examples/js/document_new.js
+++ b/examples/js/document_new.js
@@ -8,24 +8,24 @@ function create_a_document () {
     var titles = [ "The Fault in Our Stars", "Pride & Prejudice", "Nine Stories" ];
 
     try {
-       let doc = GXml.Document.new ();
-       let root = doc.create_element ("Bookshelf");
-       doc.append_child (root);
-       let owner = doc.create_element ("Owner");
-       root.append_child (owner);
-       owner.set_attribute ("fullname", "John Green");
+        let doc = GXml.GomDocument.new ();
+        let root = doc.create_element ("Bookshelf");
+        doc.append_child (root);
+        let owner = doc.create_element ("Owner");
+        root.append_child (owner);
+        owner.set_attribute ("fullname", "John Green");
 
-       let books = doc.create_element ("Books");
-       root.append_child (books);
+        let books = doc.create_element ("Books");
+        root.append_child (books);
 
-       for (var i = 0; i < authors.length; i++) {
-           let book = doc.create_element ("Book");
-           book.set_attribute ("author", authors[i]);
-           book.set_attribute ("title", titles[i]);
-           books.append_child (book);
-       }
+        for (var i = 0; i < authors.get_length (); i++) {
+            let book = doc.create_element ("Book");
+            book.set_attribute ("author", authors[i]);
+            book.set_attribute ("title", titles[i]);
+            books.append_child (book);
+        }
 
-       print ("create_a_document:\n" + doc.to_string (true, 4));
+       print ("create_a_document:\n" + doc.write_string ());
     } catch (error) {
        print (error.message);
     }
diff --git a/examples/js/document_new_from_file.js b/examples/js/document_new_from_file.js
index f29eeca..9413f8a 100755
--- a/examples/js/document_new_from_file.js
+++ b/examples/js/document_new_from_file.js
@@ -6,8 +6,8 @@ const Gio = imports.gi.Gio;
 function create_a_document_from_a_file () {
     let file = Gio.File.new_for_path ("bookshelf.xml");
     let can = new Gio.Cancellable ();
-    let doc = GXml.Document.from_gfile (file, can);
-    print ("create_a_document_from_a_file:\n" + doc.to_string (true, 4));
+    let doc = GXml.GomDocument.from_file (file, can);
+    print ("create_a_document_from_a_file:\n" + doc.write_string ());
 }
 
 create_a_document_from_a_file ();
diff --git a/examples/js/document_new_from_path.js b/examples/js/document_new_from_path.js
index 6d4431c..4325cb0 100755
--- a/examples/js/document_new_from_path.js
+++ b/examples/js/document_new_from_path.js
@@ -4,8 +4,8 @@ const GXml = imports.gi.GXml;
 const Gio = imports.gi.Gio;
 
 function create_a_document_from_a_path () {
-    let doc = GXml.Document.from_path ( "bookshelf.xml");
-    print ("create_a_document_from_a_path:\n" + doc.to_string (true, 4));
+    let doc = GXml.GomDocument.from_path ( "bookshelf.xml");
+    print ("create_a_document_from_a_path:\n" + doc.write_string ());
 }
 
 create_a_document_from_a_path ();
diff --git a/examples/js/document_new_from_string.js b/examples/js/document_new_from_string.js
index f286af0..2586920 100755
--- a/examples/js/document_new_from_string.js
+++ b/examples/js/document_new_from_string.js
@@ -13,8 +13,8 @@ function create_a_document_from_a_string () {
 <Book author=\"J.D. Salinger\" title=\"Nine Stories\"/>\
 </Books>\
 </Bookshelf>";
-    let doc = GXml.Document.from_string (xml);
-    print ("create_a_document_from_a_string:\n" + doc.to_string (true, 4));
+    let doc = GXml.GomDocument.from_string (xml);
+    print ("create_a_document_from_a_string:\n" + doc.write_string ());
     
 }
 
diff --git a/examples/js/document_properties.js b/examples/js/document_properties.js
index b154fc9..028df39 100755
--- a/examples/js/document_properties.js
+++ b/examples/js/document_properties.js
@@ -2,18 +2,20 @@
 
 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 &amp; Prejudice\"/><Book author=\"J.D. Salinger\" title=\"Nine Stories\"/></Books></Bookshelf>";
-let doc = GXml.Document.from_string (xml);
+let xml = "<?xml version=\"1.0\"?><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>";
+let doc = GXml.GomDocument.from_string (xml);
+print ("Parsed: "+doc.write_string ());
 
 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");
+// To be implemented
+//print ("The document's doctype is: " + doc.doctype.node_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");
+       " (always true - FIXME)\n");
 
 print ("Document has root element with name: " + doc.document_element.node_name + " (should be 
'Bookshelf')");
diff --git a/examples/js/document_save_to_path.js b/examples/js/document_save_to_path.js
index a86af1d..3e756f9 100755
--- a/examples/js/document_save_to_path.js
+++ b/examples/js/document_save_to_path.js
@@ -4,8 +4,10 @@ const GXml = imports.gi.GXml;
 const Gio = imports.gi.Gio;
 
 function saving_a_document_to_a_path () {
-    let doc = GXml.Document.from_path ("bookshelf.xml");
-    doc.save_to_path ("output/bookshelf_save_to_path.xml");
+    let doc = GXml.GomDocument.from_path ("bookshelf.xml");
+    var f = Gio.File.new_for_path ("bookshelf_save_to_path.xml")
+    doc.write_file (f);
+    if (!f.query_exists (null)) print ("Can't create file");
 }
 
 saving_a_document_to_a_path ();
diff --git a/examples/js/element.js b/examples/js/element.js
index 4b01901..29c4a1b 100755
--- a/examples/js/element.js
+++ b/examples/js/element.js
@@ -6,42 +6,42 @@ const GXml = imports.gi.GXml;
    view the node examples */
 
 // Setup 1
-var doc = GXml.Document.from_string ("<Tree type='leafy' wisdom='great'>Yggdrasil</Tree>");
+var doc = GXml.GomDocument.from_string ("<Tree type='leafy' wisdom='great'>Yggdrasil</Tree>");
 var tree = doc.document_element;
 
-print ("Stringify Tree element:\n" + tree.to_string (true, 0));
+print ("Stringify Tree element:\n" + tree.write_string ());
 
 print ("\nGet Tree element's tag name:\n  " + tree.tag_name);
 print ("\nGet Tree element's content:\n  " + tree.content);
 print ("\nGet Tree element's 'type' attribute:\n  " + tree.get_attribute ('type'));
 
 tree.set_attribute ("type", "lush");
-print ("\nChange Tree element's 'type' to something else:\n  " + tree.to_string (true, 0));
+print ("\nChange Tree element's 'type' to something else:\n  " + tree.write_string ());
 
 tree.set_attribute ("roots", "abundant");
-print ("\nSet a new attribute, 'roots':\n  " + tree.to_string (true, 0));
+print ("\nSet a new attribute, 'roots':\n  " + tree.write_string ());
 
 tree.remove_attribute ("type");
-print ("\nRemove attribute 'type':\n  " + tree.to_string (true, 0));
+print ("\nRemove attribute 'type':\n  " + tree.write_string ());
 
-var new_attr = doc.create_attribute ("height");
-new_attr.value = "109m";
-tree.set_attribute_node (new_attr);
-print ("\nSet a new attribute node:\n  " + tree.to_string (true, 0));
+tree.set_attribute ("height", "109m");
+print ("\nSet a new attribute node:\n  " + tree.write_string ());
 
-var old_attr = tree.get_attribute_node ("wisdom");
-print ("\nGet an existing attr as a node:\n  " + old_attr.to_string (true, 0));
+var old_attr = tree.get_attribute ("wisdom");
+print ("\nGet an existing attr as a node:\n  " + old_attr);
 
-tree.remove_attribute_node (old_attr);
-print ("\nRemove wisdom attr by its node:\n  " + tree.to_string (true, 0));
+tree.remove_attribute (old_attr);
+print ("\nRemove wisdom attr by its node:\n  " + tree.write_string ());
 
 // Setup 2
-var leaves_doc = GXml.Document.from_string ("<Leaves><Leaf name='Aldo' /><Leaf name='Drona' /><Leaf 
name='Elma' /><Leaf name='Hollo' /><Leaf name='Irch' /><Leaf name='Linder' /><Leaf name='Makar' /><Leaf 
name='Oakin' /><Leaf name='Olivio' /><Leaf name='Rown' /></Leaves>");
+var leaves_doc = GXml.GomDocument.from_string ("<Leaves><Leaf name='Aldo' /><Leaf name='Drona' /><Leaf 
name='Elma' /><Leaf name='Hollo' /><Leaf name='Irch' /><Leaf name='Linder' /><Leaf name='Makar' /><Leaf 
name='Oakin' /><Leaf name='Olivio' /><Leaf name='Rown' /></Leaves>");
 var leaves = leaves_doc.document_element;
 
-print ("Our second example:\n" + leaves_doc.to_string (true, 0));
+print ("Our second example:\n" + leaves_doc.write_string ());
 var leaf_list = leaves_doc.get_elements_by_tag_name ("Leaf");
-print ("Show element descendants of Leaves with the tag name Leaf:\n  " + leaf_list.to_string (true));
+print ("Show element descendants of Leaves with the tag name Leaf:\n  ");
+for (var i = 0; i < leaf_list.get_length (); i++) {
+       var e = leaf_list.get_element (i);
+       print ("Element: "+e.write_string ());
+}
 
-/* TODO: when we support sibling text nodes (that is, when we're not
- * using libxml2), then we can add a normalize () example */
diff --git a/examples/js/node_child_management.js b/examples/js/node_child_management.js
index 272b676..ee64635 100755
--- a/examples/js/node_child_management.js
+++ b/examples/js/node_child_management.js
@@ -1,25 +1,23 @@
 #!/usr/bin/gjs
 
-/* https://bugzilla.gnome.org/show_bug.cgi?id=706907
-   Sadly, we can't handle GHashTables as properties in gjs yet :( */
-var bug_706907_bypass = true;
-
 const GXml = imports.gi.GXml;
 
 /* Setup */
-var doc = GXml.Document.from_path ("bookshelf_node.xml");
+var doc = GXml.GomDocument.from_path ("bookshelf_node.xml");
 var bookshelf = doc.document_element;
-var date_clone_shallow = date_today.clone_node (false);
-var date_clone_deep = date_today.clone_node (true);
-
-/* Appending a child */
 var date_today = doc.create_element ("Date");
+date_today.append_child (doc.create_text_node ("Today"));
 bookshelf.append_child (date_today);
+var date_clone_shallow = date_today.clone_node (false);
+bookshelf.append_child (date_clone_shallow);
+var date_clone_deep = date_today.clone_node (true);
+bookshelf.append_child (date_clone_deep);
+if (!bookshelf.child_nodes.contains (date_clone_deep)) print ("Date Clone Deep not present!");
 
 var date_today_text = doc.create_text_node ("Today");
 date_today.append_child (date_today_text);
 
-print ("Bookshelf after appending a new element:\n" + bookshelf.to_string (true, 0) + "\n\n");
+print ("Bookshelf after appending a new element:\n" + bookshelf.write_string () + "\n\n");
 
 /* Checking whether children exist */
 print ("Does Bookshelf have child nodes? " + bookshelf.has_child_nodes () + "\n");
@@ -28,17 +26,17 @@ print ("Does the shallow Date clone have child nodes? " +
 
 /* Accessing the first child */
 var bookshelf_first_child = bookshelf.first_child;
-print ("Bookshelf's first child:\n" + bookshelf_first_child.to_string (true, 0) + "\n\n");
+print ("Bookshelf's first child:\n" + bookshelf_first_child.write_string () + "\n\n");
 
-var date_clone_cur_text = date_clone_deep.first_child;
-print ("Our deep clone's first child:\n" + date_clone_cur_text.to_string (true, 0) + "\n\n");
+var date_clone_cur_text = date_clone_deep.child_nodes.item (0);
+print ("Our deep clone's first child:\n" + date_clone_cur_text.data + "\n\n");
 
 /* Replacing a child */
 var date_clone_new_text = doc.create_text_node ("Tomorrow");
 date_clone_deep.replace_child (date_clone_new_text, date_clone_cur_text);
 
 print ("Bookshelf after replacing the Text of our deep clone of Date:\n" +
-       bookshelf.to_string (true, 0) + "\n\n");
+       bookshelf.write_string () + "\n\n");
 
 /* Inserting a new child before an existing child */
 var date_yesterday = doc.create_element ("Date");
@@ -48,17 +46,17 @@ date_yesterday.append_child (date_yesterday_text);
 bookshelf.insert_before (date_yesterday, date_today);
 
 print ("Bookshelf after inserting Date Yesterday before Date Today:\n" +
-       bookshelf.to_string (true, 0) + "\n\n");
+       bookshelf.write_string () + "\n\n");
 
 /* Removing a child */
 bookshelf.remove_child (date_clone_shallow);
 
 print ("Bookshelf after removing the shallow date clone:\n" +
-       bookshelf.to_string (true, 0) + "\n\n");
+       bookshelf.write_string () + "\n\n");
 
 /* Accessing the last child */
 var last_child = bookshelf.last_child;
-print ("Bookshelf's last child:\n" + last_child.to_string (true, 0) + "\n\n");
+print ("Bookshelf's last child:\n" + last_child.write_string () + "\n\n");
 
 /* Traversing children via next and previous sibling */
 var cur_child = null;
@@ -67,7 +65,7 @@ var i = 0;
 print ("Bookshelf's children, using next_sibling from the first_child:\n");
 for (cur_child = bookshelf.first_child; cur_child != null;
      cur_child = cur_child.next_sibling) {
-    print ("  Child " + i + "\n    " + cur_child.to_string (true, 2) + "\n");
+    print ("  Child " + i + "\n    " + cur_child.write_string () + "\n");
     i++;
 }
 
@@ -75,7 +73,7 @@ print ("Bookshelf's children, using previous_sibling from the last_child:\n");
 for (cur_child = bookshelf.last_child; cur_child != null;
      cur_child = cur_child.previous_sibling) {
     i--;
-    print ("  Child " + i + "\n    " + cur_child.to_string (true, 2) + "\n");
+    print ("  Child " + i + "\n    " + cur_child.write_string () + "\n");
 }
 print ("\n");
 
@@ -85,15 +83,17 @@ var children = bookshelf.child_nodes;
 var len = children.length;
 print ("Bookshelf's children, using get_child_nodes and incrementing by index:\n");
 for (i = 0; i < len; i++) {
-    var child = children.nth (i);
-    print ("  Child " + i + "\n    " + child.to_string (true, 2) + "\n");
+    var child = children.item (i);
+    print ("  Child " + i + "\n    " + child.write_string () + "\n");
 }
 print ("\n");  
 
 
 /* Access the parent node from a node */
+var ln = bookshelf.get_elements_by_tag_name ("Book");
+var first_book = ln.get_element (0);
 var first_book_parent = first_book.parent_node;
-print ("The parent of " + first_book.to_string (true, 0) + " looks like:\n  " +
-       first_book_parent.to_string (true, 1) + "\n\n");
+print ("The parent of " + first_book.write_string () + " looks like:\n  " +
+       first_book_parent.write_string () + "\n\n");
 
 
diff --git a/examples/js/node_list.js b/examples/js/node_list.js
index 881ed52..721bccb 100755
--- a/examples/js/node_list.js
+++ b/examples/js/node_list.js
@@ -5,65 +5,19 @@ const GXml = imports.gi.GXml;
 /* For more examples, view node's child management code */
 
 // Setup
-var doc = GXml.Document.from_string ("<Refrigerator><Food name='cheese' /><Food name='tomatoes' /><Food 
name='avocado' /></Refrigerator>");
+var doc = GXml.GomDocument.from_string ("<Refrigerator><Food name='cheese' /><Food name='tomatoes' /><Food 
name='avocado' /></Refrigerator>");
 
 var foods_list = doc.get_elements_by_tag_name ("Food");
 
 
-print ("Our refrigerator:\n" + doc.to_string (true, 0));
+print ("Our refrigerator:\n" + doc.write_string ());
 
-print ("\nThe length of the list:\n  " + foods_list.length);
-
-print ("\nStringify the list:\n  " + foods_list.to_string (true));
+print ("\nThe length of the list:  " + foods_list.get_length ()+"\n");
 
 print ("\nAccessing the second food item from a nodelist using .item ():\n  " +
        foods_list.item (1).get_attribute ('name'));
 
-print ("\nAccessing the second food item from a nodelist using .nth ():\n  " +
-       foods_list.nth (1).get_attribute ('name'));
-
-print ("\nAccessing the second food item from a nodelist using .nth_data ():\n  " +
-       foods_list.nth_data (1).get_attribute ('name'));
-
-print ("\nAccessing the first food item with .first:\n  " +
-       foods_list.first ().get_attribute ('name'));
-
-print ("\nAccessing the last food item with .last:\n  " +
-       foods_list.last ().get_attribute ('name'));
-
-print ("\nAccessing the food item 2 previous to the last with .nth_prev ():\n  " +
-       foods_list.nth_prev (foods_list.last (), 2).get_attribute ('name'));
-
-print ("\nFinding the index for the last food item with .find ():\n  " +
-       foods_list.find (foods_list.last ()));
-
-print ("\nFinding the index for the last food item with .position ():\n  " +
-       foods_list.position (foods_list.last ()));
-
-print ("\nFinding the index for the last food item with .index ():\n  " +
-       foods_list.index (foods_list.last ()));
-
-/* TODO: this isn't wonderfully efficient; we want to do a foreach
-   style loop on it, for (var a : list) {..., or have a NodeList thing
-   to get the next one */
-print ("Traverse the list:");
-for (var i = 0; i < foods_list.length; i++) {
-    var food = foods_list.nth (i);
-    print ("  " + i + ":" + food.to_string (true, 0));
+for (var i = 0; i < foods_list.get_length (); i++) {
+    var food = foods_list.item (i);
+    print ("  " + i + ":" + food.write_string ());
 }
-
-/* TODO:
-   Figure out how to handle GFunc 
-print ("\nOperate on each food item using .foreach ()\n");
-foods_list.foreach (function (a) {
-    });
-*/
-
-/* TODO:
-   Figure out how to handle GCompareFunc
-print ("\nFinding the index for the food item with the same name, using .find_custom ():\n" +
-       foods_list.find_custom (foods_list.last (), function (a, b) {
-          print ("DBG: " + a + "; " + b + "; ");
-          return 2;
-       }, foods_list));
-*/
diff --git a/examples/js/node_self.js b/examples/js/node_self.js
index 7fb08a9..7ef8973 100755
--- a/examples/js/node_self.js
+++ b/examples/js/node_self.js
@@ -1,20 +1,16 @@
 #!/usr/bin/gjs
 
-/* https://bugzilla.gnome.org/show_bug.cgi?id=706907
-   Sadly, we can't handle GHashTables as properties in gjs yet :( */
-var bug_706907_bypass = true;
-
 const GXml = imports.gi.GXml;
 
 /* Setup */
-var doc = GXml.Document.from_path ("bookshelf_node.xml");
+var doc = GXml.GomDocument.from_path ("bookshelf_node.xml");
 var bookshelf = doc.document_element;
 var date_today = doc.create_element ("Date");
 date_today.append_child (doc.create_text_node ("Today"));
 
 
 /* Stringification */
-print ("Stringifying bookshelf:\n" + bookshelf.to_string (true, 0) + "\n\n");
+print ("Stringifying bookshelf:\n" + bookshelf.write_string () + "\n\n");
 
 /* Adding clones */
 var date_clone_shallow = date_today.clone_node (false);
@@ -23,35 +19,32 @@ var date_clone_deep = date_today.clone_node (true);
 bookshelf.append_child (date_clone_shallow);
 bookshelf.append_child (date_clone_deep);
 
-print ("Bookshelf after adding clones:\n" + bookshelf.to_string (true, 0) + "\n\n");
+print ("Bookshelf after adding clones:\n" + bookshelf.write_string () + "\n\n");
 
-/* Access the node's attributes map - note that this only applies to Elements
-   http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1841493061 */
 var book_list = doc.get_elements_by_tag_name ("Book");
-var first_book = book_list.first ();
-
-if (! bug_706907_bypass) {
-    var attrs = first_book.attributes;
-    
-    print ("List attributes from element: " + first_book.to_string (false, 0) + "\n");
-    for (attrs_keys = attrs.get_keys (); attrs_keys != null; attrs_keys = attrs_keys.next) {
-       var attr = attrs.lookup (attrs_keys.data);
-       print ("  " + attr.name + " => " + attr.value +
-              "  (" + (attr.specified ? "specified" : "not specified") + ")\n");
-    }
-    print ("\n");
-}
+print (book_list.constructor)
+print ("Book nodes found: "+book_list.get_length ());
+var first_book = book_list.get_element (0);
+
+var ath = first_book.get_attribute ("author");
+var att = first_book.get_attribute ("title");
+print ("Autor: "+ath+" Title: "+att);
+
+var attrs = first_book.get_attributes ();
+print ("Attrs type:"+attrs.constructor);
+
+print ("\n");
 
 /* Access the owner document from the node */
-var owner_document = bookshelf.owner_document;
+var owner_document = bookshelf.get_owner_document ();
 
-print ("The owner document for Bookshelf looks like:\n" + owner_document.to_string (false, 0) + "\n\n");
+print ("The owner document for Bookshelf looks like:\n" + owner_document.write_string () + "\n\n");
 
 /* Check node types */
 var author_attr = first_book.get_attribute ("author");
 
 print ("A:");
-for (x in GXml.NodeType) {
+for (var x in GXml.NodeType) {
     print (x);
 }
 var test = GXml.NodeType['DOCUMENT'];
diff --git a/examples/js/text.js b/examples/js/text.js
index 32859ea..bbf7e0f 100755
--- a/examples/js/text.js
+++ b/examples/js/text.js
@@ -3,29 +3,29 @@
 const GXml = imports.gi.GXml;
 
 // Setup
-var doc = new GXml.Document.new ();
+var doc = GXml.GomDocument.new ();
 doc.append_child (doc.create_element ("Diary"));
 
 var text = doc.create_text_node ("I am the very model of a modern Major General.");
 
 print ("Document before inserting text:\n" +
-       doc.to_string (true, 0));
+       doc.write_string ());
 
 doc.document_element.append_child (text);
 
 print ("Document after inserting text:\n" +
-       doc.to_string (true, 0));
+       doc.write_string ());
 
 print ("Nodes of document element 'Diary' before split_text:");
 for (var node = doc.document_element.first_child; node != null; node = node.next_sibling) {
-    print ("  Node: " + node.to_string (true, 0));
+    print ("  Node: " + node.get_node_name()+":"+node.get_node_value ());
 }
 
 text.split_text (20);
 
 print ("\nNodes of document element 'Diary' after split_text:");
 for (var node = doc.document_element.first_child; node != null; node = node.next_sibling) {
-    print ("  Node: " + node.to_string (true, 0));
+    print ("  Node: " + node.get_node_name()+":"+node.get_node_value ());
 }
 
 print ("\nWARNING: the above does not work as desired, since libxml2 automatically merges neighbouring Text 
nodes.  You should see two Nodes for each part of the split.  This will hopefully be addressed in the 
future.");
diff --git a/gxml/GomNode.vala b/gxml/GomNode.vala
index 1ae3acc..ed8d83d 100644
--- a/gxml/GomNode.vala
+++ b/gxml/GomNode.vala
@@ -312,7 +312,7 @@ public class GXml.GomNode : Object,
     return insert_before (node, null);
   }
   public DomNode replace_child (DomNode node, DomNode child) throws GLib.Error {
-    if (!(node is GXml.GNode))
+    if (!(node is GXml.GomNode))
       throw new DomError.INVALID_NODE_TYPE_ERROR (_("Invalid attempt to add invalid node type"));
     if (child == null || !this.contains (child))
       throw new DomError.NOT_FOUND_ERROR (_("Can't find child node to replace or child have a different 
parent"));


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