[seed] examples: Add three xml module examples. xml-dom, xml-tree, and xml-xpath.



commit 1cc7555614faeb5d886a7fd25e5838e3109aace7
Author: Robert Carr <racarr svn gnome org>
Date:   Wed May 13 15:52:59 2009 -0400

    examples: Add three xml module examples. xml-dom, xml-tree, and xml-xpath.
---
 configure.ac                                |    1 +
 doc/index.html                              |   10 +++++++---
 examples/Makefile.am                        |    1 +
 {modules/libxml => examples/xml}/sample.xml |    0
 examples/xml/xml-dom.js                     |   16 ++++++++++++++++
 examples/xml/xml-tree.js                    |   17 +++++++++++++++++
 examples/xml/xml-xpath.js                   |    7 +++++++
 7 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6a347f8..ac171e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -334,6 +334,7 @@ examples/twitter/Makefile
 examples/pong/Makefile
 examples/same-seed/Makefile
 examples/dbus/Makefile
+examples/xml/Makefile
 modules/Makefile
 modules/example/Makefile
 modules/sqlite/Makefile
diff --git a/doc/index.html b/doc/index.html
index 8305853..338678c 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -71,9 +71,13 @@ Seed has a wide variety of examples <a href="http://git.gnome.org/cgit/seed/tree
 <li><a href="http://git.gnome.org/cgit/seed/tree/examples/clutter-pad.js";>clutter-pad</a> - An example to prototype Clutter scripts using a GtkSourceView widget and a GtkClutter stage. Demonstrates usage of sandbox module.</li>
 <li><a href="http://git.gnome.org/cgit/seed/tree/examples/pango-fontset.js";>pango-fontset</a> - Demonstrates basic Pango usage (for querying font information) </li>
 <li><a href="http://git.gnome.org/cgit/seed/tree/examples/pango.js";>pango</a> - Demonstrates a bit more complicated Pango usage, and Clutter usage, to create a sort of font playground. </li>
-<li><a href="http://git.gnome.org/cgit/seed/tree/examples/dbus-banshee.js";>dbus-banshee</a> - Demonstrates the use of DBus to control Banshee </li>
-<li><a href="http://git.gnome.org/cgit/seed/tree/examples/dbus-consolekit.js";>dbus-consolekit</a> - Demonstrates the use of DBus to query ConsoleKit </li>
-<li><a href="http://git.gnome.org/cgit/seed/tree/examples/dbus-networkmanager.js";>dbus-networkmanager</a> - Demonstrates the use of DBus to query NetworkManager </li>
+<li><a href="http://git.gnome.org/cgit/seed/tree/examples/dbus/dbus-banshee.js";>dbus-banshee</a> - Demonstrates the use of DBus to control Banshee. </li>
+<li><a href="http://git.gnome.org/cgit/seed/tree/examples/dbus/dbus-consolekit.js";>dbus-consolekit</a> - Demonstrates the use of DBus to query ConsoleKit. </li>
+<li><a href="http://git.gnome.org/cgit/seed/tree/examples/dbus/dbus-networkmanager.js";>dbus-networkmanager</a> - Demonstrates the use of DBus to query NetworkManager. </li>
+<li><a href="http://git.gnome.org/cgit/seed/tree/examples/xml/xml-dom.js";>xml-dom</a> - Demonstrates the use of the libxml module for basic document access using DOM methods.</li>
+<li><a href="http://git.gnome.org/cgit/seed/tree/examples/xml/xml-xpath.js";>xml-xpath</a> - Demonstrates the use of the libxml module for basic document access using XPath. </li>
+<li><a href="http://git.gnome.org/cgit/seed/tree/examples/xml/xml-tree.js";>xml-tree</a> - Demonstrates the use of the libxml module for basic document access using the document tree. </li>
+
 
 </ul>
 
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 8d20c25..4dbad65 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -9,6 +9,7 @@ SUBDIRS = \
     pong \
     same-seed \
     turtle \
+    xml \
     twitter
 
 repldir = $(datadir)/seed
diff --git a/modules/libxml/sample.xml b/examples/xml/sample.xml
similarity index 100%
rename from modules/libxml/sample.xml
rename to examples/xml/sample.xml
diff --git a/examples/xml/xml-dom.js b/examples/xml/xml-dom.js
new file mode 100755
index 0000000..7579c72
--- /dev/null
+++ b/examples/xml/xml-dom.js
@@ -0,0 +1,16 @@
+#!/usr/local/bin/seed
+xml = imports.libxml
+
+doc = xml.parseFile("sample.xml");
+
+root = doc.root;
+storyinfos = root.getElementsByTagName("storyinfo");
+for (var i = 0; i < storyinfos.length; i++){
+    var info = storyinfos[i];
+    var keyword = info.getElementsByTagName("keyword")[0];
+    
+    Seed.printf ("Story info Keyword (example: %s): %s", 
+		 keyword.getAttribute("example"),
+		 keyword.content);
+		 
+}
diff --git a/examples/xml/xml-tree.js b/examples/xml/xml-tree.js
new file mode 100755
index 0000000..e56cb1b
--- /dev/null
+++ b/examples/xml/xml-tree.js
@@ -0,0 +1,17 @@
+#!/usr/local/bin/seed
+xml = imports.libxml;
+
+function print_element (element){
+    var child = element.children;
+
+    while (child){
+	if (child.type == "element"){
+	    Seed.print(child.name + ": " + child.content);
+	    print_element (child);
+	}
+	child = child.next;
+    }
+}
+
+doc = xml.parseFile("sample.xml");
+print_element (doc.root);
diff --git a/examples/xml/xml-xpath.js b/examples/xml/xml-xpath.js
new file mode 100755
index 0000000..b503e62
--- /dev/null
+++ b/examples/xml/xml-xpath.js
@@ -0,0 +1,7 @@
+#!/usr/local/bin/seed
+xml = imports.libxml;
+doc = xml.parseFile("./sample.xml");
+ctx = doc.xpathNewContext();
+
+results = ctx.xpathEval("//story/body/headline");
+Seed.print("Headline: " + results.value[0].content);



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