[seed] xml: Bind xmlParseMemory as xml.parseString



commit 52f85a828777e932191cc0f70d325e15da9c27c2
Author: Robert Carr <racarr svn gnome org>
Date:   Wed May 13 01:09:27 2009 -0400

    xml: Bind xmlParseMemory as xml.parseString
---
 doc/index.html          |    2 +-
 modules/libxml/libxml.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/doc/index.html b/doc/index.html
index ee0c802..c34f129 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -108,7 +108,7 @@ A module which allows execution of code in isolated sandboxes, with new global o
 
 <div class="subsection"><b>dbus</b></div>
 <p>
-A module which allows usage of DBus. Not yet documented, but see the <a href="http://git.gnome.org/cgit/seed/tree/examples/banshee-dbus.js";>banshee-dbus</a> example.
+A module which allows usage of DBus. Not yet documented, but see the <a href="http://git.gnome.org/cgit/seed/tree/examples/dbus-banshee.js";>dbus-banshee</a> or <a href="http://git.gnome.org/cgit/seed/tree/examples/dbus-consolekit.js";>dbus-consolekit</a> examples.
 </p>
 <div class="subsection"><b>libxml</b></div>
 <p>
diff --git a/modules/libxml/libxml.c b/modules/libxml/libxml.c
index a780512..8159dd7 100644
--- a/modules/libxml/libxml.c
+++ b/modules/libxml/libxml.c
@@ -107,6 +107,39 @@ seed_xml_parse_file (SeedContext ctx,
   return ret;
 }
 
+static SeedValue 
+seed_xml_parse_string (SeedContext ctx,
+		       SeedObject function,
+		       SeedObject this_object,
+		       gsize argument_count,
+		       const SeedValue arguments[],
+		       SeedException * exception)
+{
+  SeedObject ret;
+  xmlDocPtr doc;
+  gchar *string;
+  if (argument_count != 1)
+    {
+      seed_make_exception (ctx, exception, "ArgumentError",
+			   "parseString expected 1 argument, got %d",
+			   argument_count);
+      return seed_make_null (ctx);
+    }
+  string = seed_value_to_string (ctx, arguments[0], exception);
+  doc = xmlParseMemory (string, strlen (string));
+  if (!doc)
+    {
+      seed_make_exception (ctx, exception, "XMLError",
+			   "Document not parsed successfully");
+      g_free (string);
+      return seed_make_null (ctx);
+    }
+  ret = seed_make_xml_doc (ctx, doc);
+
+  g_free (string);
+  return ret;
+}
+
 static SeedValue
 seed_xml_doc_get_root (SeedContext ctx,
 		       SeedObject object,
@@ -472,6 +505,9 @@ seed_libxml_define_stuff ()
   seed_create_function (eng->context, "parseFile", 
 			(SeedFunctionCallback) seed_xml_parse_file,
 			namespace_ref);
+  seed_create_function (eng->context, "parseString", 
+			(SeedFunctionCallback) seed_xml_parse_string,
+			namespace_ref);
 
   node_proto = seed_object_get_prototype (eng->context,
 					  seed_make_object (eng->context, 



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