[gxml] * Removed custom libxml-2.0.vapi file * Added gxml/xlibxml.c/.h and xlibxml.vapi files to implement



commit 45d079c8e3877cec9f7d9ad190368e62b5fed1d9
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Apr 30 11:26:50 2015 -0500

    * Removed custom libxml-2.0.vapi file
    * Added gxml/xlibxml.c/.h and xlibxml.vapi files to implement missing API from
      Vala's libxml-2.0.vapi file (updates to new GXml.Xmlx API)
    * Old libxml-DocumentType uses a Xml.Doc to access its internals
    * Fixed get_last_error to_string implementation to use string.replace()
    * GXml.Node.namespaces changed to Gee.List<Namespace> (updated implementations)
    * Added GXml.Node.set_namespace (currently is buggy)
    * Added GXml.Serializable.set_namespace and removed serializable_set_namespace
      property (updated implementations)
    * Old libxml-Node and BackedNode changed type from NodeList to List<Namespace>
      this change doesn't broke DOM API
    * Reimplemented libxml-NamespaceAttrNodeList to access directly to Xml.Node.Ns
      lists of namespaces and implement Gee.List<Namespace> interfaces

 gxml/Makefile.am                       |    7 +-
 gxml/Node.vala                         |    3 +-
 gxml/Serializable.vala                 |   14 +-
 gxml/SerializableGeeArrayList.vala     |    2 +-
 gxml/SerializableGeeDualKeyMap.vala    |    2 +-
 gxml/SerializableGeeHashMap.vala       |    2 +-
 gxml/SerializableGeeTreeMap.vala       |    2 +-
 gxml/SerializableJson.vala             |    2 +-
 gxml/SerializableObjectModel.vala      |    8 +-
 gxml/libxml-BackedNode.vala            |   40 +-
 gxml/libxml-CharacterData.vala         |    2 +-
 gxml/libxml-Document.vala              |   14 +-
 gxml/libxml-DocumentType.vala          |    8 +-
 gxml/libxml-Error.vala                 |    4 +-
 gxml/libxml-NamespaceAttrNodeList.vala |  167 +++-
 gxml/libxml-Node.vala                  |    4 +-
 gxml/xlibxml.c                         |   42 +
 gxml/xlibxml.h                         |   32 +
 test/DocumentTest.vala                 |    4 +-
 test/ElementTest.vala                  |   16 +-
 test/SerializableObjectModelTest.vala  |   23 +-
 vapi/libxml-2.0.vapi                   | 2021 --------------------------------
 vapi/xlibxml-1.0.vapi                  |   31 +
 23 files changed, 331 insertions(+), 2119 deletions(-)
---
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index 9f5386f..3afa6d9 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -94,6 +94,7 @@ AM_VALAFLAGS += \
        $(ERROR_VALAFLAGS) \
        --library=gxml-0.6 \
        $(top_srcdir)/vapi/config.vapi \
+       $(top_srcdir)/vapi/xlibxml-1.0.vapi \
        --vapidir=. \
        --vapidir=$(top_srcdir)/vapi \
        --pkg libxml-2.0 \
@@ -122,13 +123,15 @@ gxml_0_6_la_vala.stamp: $(sources)
 
 $(sources:.vala=.c): gxml_0_6_la_vala.stamp
 
-libgxml_0_6_la_SOURCES=$(sources:.vala=.c)
+libgxml_0_6_la_SOURCES= \
+  $(sources:.vala=.c) \
+  xlibxml.c
 libgxml_0_6_la_DEPENDENCIES= gxml_0_6_la_vala.stamp
 
 # .h header file
 gxml.h: gxml_0_6_la_vala.stamp
 gxmldir= $(includedir)/gxml-$(API_VERSION)/gxml
-gxml_HEADERS = gxml.h
+gxml_HEADERS = gxml.h xlibxml.h
 
 # .vapi Vala API file
 gxml-0.6.vapi: gxml_0_6_la_vala.stamp
diff --git a/gxml/Node.vala b/gxml/Node.vala
index 45b4442..c4e4080 100644
--- a/gxml/Node.vala
+++ b/gxml/Node.vala
@@ -24,7 +24,7 @@ using Gee;
 
 public interface GXml.Node : Object
 {
-  public abstract Gee.BidirList<GXml.Namespace> namespaces { get; }
+  public abstract Gee.List<GXml.Namespace> namespaces { get; }
   public abstract Gee.BidirList<GXml.Node> childs { get; }
   public abstract Gee.Map<string,GXml.Node> attrs { get; }
   public abstract string name { get; }
@@ -32,6 +32,7 @@ public interface GXml.Node : Object
   public abstract GXml.NodeType type_node { get; }
   public abstract GXml.Document document { get; }
   public abstract string to_string ();
+  public abstract bool set_namespace (string uri, string prefix);
   public virtual string ns_prefix () { return namespaces.first ().prefix; }
   public virtual string ns_urf () { return namespaces.first ().uri; }
 }
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index df5bbc6..2c3210e 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -82,7 +82,7 @@ namespace GXml {
     public abstract HashTable<string,GXml.xNode>    unknown_serializable_property { get; protected set; }
 
     /**
-     * Used to add content in an { link GXml.xElement}.
+     * Used to add content in an { link GXml.Element}.
      *
      * By default no contents is serialized/deseralized. Implementors must implement
      * { link Serializable.serialize_use_xml_node_value} function returning
@@ -97,22 +97,22 @@ namespace GXml {
     public abstract string?  serialized_xml_node_value { get; protected set; default = null; }
 
     /**
-     * Used to set specific namespace for an { link GXml.xElement}.
+     * Used to set specific namespace for an { link GXml.Element}.
      *
-     * By default no namspace prefix is added to { link GXml.xElement} on serialized. Implementors
+     * By default no namspace prefix is added to { link GXml.Element} on serialized. Implementors
      * must consider { link Serializable.serialize_set_namespace} proterty value
      * to discover if this node should have a namespace.
      *
-     * { link GXml.xElement} namespace should be added before to serialize any
+     * { link GXml.Element} namespace should be added before to serialize any
      * property.
      *
      * This property should have a format "prefix|url".
      *
      * This property is ignored on serialisation.
      */
-    public abstract string? serialize_set_namespace { get; set; default = null; }
+    public abstract bool set_namespace (GXml.Node node);
       /**
-      * Used to check { link GXml.xElement}'s contents must be deseralized.
+      * Used to check { link GXml.Element}'s contents must be deseralized.
       * 
       * By default GXml's implementations doesn't deseriaze/serialize XML node contents.
       * In order to enable it, you must override { link serialize_use_xml_node_value}
@@ -155,7 +155,7 @@ namespace GXml {
     public abstract GXml.Node? serialize (GXml.Node node) throws GLib.Error;
 
     /**
-     * Serialize a property @prop on a { link GXml.xElement}.
+     * Serialize a property @prop on a { link GXml.Element}.
      * 
      * This method is called recursivally by { link serialize} method over all properties
      * to be serialized.
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 8ecd6fb..9725dd7 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -33,7 +33,7 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
   public string? serialized_xml_node_value { get; protected set; default=null; }
-  public string? serialize_set_namespace { get; set; default = null; }
+  public virtual bool set_namespace (GXml.Node node) { return true; }
 
   public GLib.HashTable<string,GXml.xNode> unknown_serializable_property { get; protected set; }
 
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index 5aea3db..5c51ef5 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -115,7 +115,7 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
   public string? serialized_xml_node_value { get; protected set; default=null; }
-  public string? serialize_set_namespace { get; set; default = null; }
+  public virtual bool set_namespace (GXml.Node node) { return true; }
   public GLib.HashTable<string,GXml.xNode> unknown_serializable_property { get; protected set; }
 
   public virtual bool get_enable_unknown_serializable_property () { return false; }
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index 50d24e9..b681197 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -31,7 +31,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
   public string? serialized_xml_node_value { get; protected set; default=null; }
-  public string? serialize_set_namespace { get; set; default = null; }
+  public virtual bool set_namespace (GXml.Node node) { return true; }
   public GLib.HashTable<string,GXml.xNode> unknown_serializable_property { get; protected set; }
 
   public virtual bool get_enable_unknown_serializable_property () { return false; }
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index e3b5369..e987315 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -31,7 +31,7 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, Ser
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
   public string? serialized_xml_node_value { get; protected set; default=null; }
-  public string? serialize_set_namespace { get; set; default = null; }
+  public virtual bool set_namespace (GXml.Node node) { return true; }
   public GLib.HashTable<string,GXml.xNode> unknown_serializable_property { get; protected set; }
 
   public bool get_enable_unknown_serializable_property () { return false; }
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index 01f67ec..f9ea4b0 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -66,7 +66,7 @@ public class GXml.SerializableJson : GLib.Object, GXml.Serializable
   public HashTable<string,GXml.xNode>    unknown_serializable_property { get; protected set; }
   public virtual bool get_enable_unknown_serializable_property () { return false; }
   public string?  serialized_xml_node_value { get; protected set; default = null; }
-  public string? serialize_set_namespace { get; set; default = null; }
+  public virtual bool set_namespace (GXml.Node node) { return true; }
 
   public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual string node_name () { return "Object"; }
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 3bb86d8..285161f 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -39,13 +39,13 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
   protected ParamSpec[] properties { get; set; }
   public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
   public string? serialized_xml_node_value { get; protected set; default=null; }
-  public string? serialize_set_namespace { get; set; default = null; }
   public virtual bool get_enable_unknown_serializable_property () { return false; }
   public GLib.HashTable<string,GXml.xNode> unknown_serializable_property { get; protected set; }
 
   public virtual bool serialize_use_xml_node_value () { return false; }
   public virtual bool property_use_nick () { return false; }
 
+  public virtual bool set_namespace (GXml.Node node) { return true; }
   public virtual string node_name ()
   {
     return default_node_name ();
@@ -112,11 +112,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
       doc = node.document;
     var element = (xElement) doc.create_element (node_name ());
     node.append_child (element);
-    if (serialize_set_namespace != null) {
-      string[] str = serialize_set_namespace.split ("|", 2);
-      ((xElement)doc.root).add_namespace_attr (str[1], str[0]);
-      element.set_namespace (str[1], str[0]);
-    }
+    set_namespace (element);
     foreach (ParamSpec spec in list_serializable_properties ()) {
       serialize_property (element, spec);
     }
diff --git a/gxml/libxml-BackedNode.vala b/gxml/libxml-BackedNode.vala
index 7ac2790..e9177b7 100644
--- a/gxml/libxml-BackedNode.vala
+++ b/gxml/libxml-BackedNode.vala
@@ -60,10 +60,10 @@ namespace GXml {
                /**
                 * { inheritDoc}
                 */
-               public override NodeList? namespace_definitions {
+               public override Gee.List<Namespace>? namespace_definitions {
                        get {
                                if (_namespace_definitions == null) {
-                                       this._namespace_definitions = new NamespaceAttrNodeList (this, 
this.owner_document);
+                                       this._namespace_definitions = new NamespaceAttrNodeList (this);
                                }
                                return this._namespace_definitions;
                        }
@@ -103,36 +103,16 @@ namespace GXml {
                 */
                public override bool set_namespace (string uri, string namespace_prefix)
                {
+                       GLib.message ("Setting a new Namespace...");
                        if (node == null) return false;
-                       if (node->ns_def != null) {
-                               for (Xml.Ns *cur = node->ns_def; cur != null; cur = cur->next) {
-                                       if ((string) cur->prefix == namespace_prefix && (string) cur->href == 
uri) {
-                                               node->set_ns (cur);
-                                               return true;
-                                       }
-                               }
-                       }
-                       // Not found search on parent
-                       if (node->parent != null) {
-                               for (Xml.Ns *cur = node->parent->ns_def; cur != null; cur = cur->next) {
-                                       if ((string) cur->prefix == namespace_prefix && (string) cur->href == 
uri) {
-                                               this.node->set_ns (cur);
-                                               return true;
-                                       }
-                               }
-                       }
-                       // Not found in this node, searching on root element
-                       if (owner_document == null) return false;
-                       if (owner_document.document_element == null) return false;
-                       if (owner_document.document_element.node == null) return false;
-                       if (owner_document.document_element.node->ns_def == null) return false;
-                       for (Xml.Ns *cur = owner_document.document_element.node->ns_def; cur != null; cur = 
cur->next) {
-                               if ((string) cur->prefix == namespace_prefix && (string) cur->href == uri) {
-                                       this.node->set_ns (cur);
-                                       return true;
-                               }
+                       Xml.Ns* ns = node->doc->search_ns_by_href (node, uri);
+                       if (ns != null) {
+                               node->set_ns (ns);
+                               return true;
                        }
-                       return false;
+                       ns = node->new_ns (uri, namespace_prefix);
+                       node->set_ns (ns);
+                       return true;
                }
                /**
                 * { inheritDoc}
diff --git a/gxml/libxml-CharacterData.vala b/gxml/libxml-CharacterData.vala
index 6c57499..e77468b 100644
--- a/gxml/libxml-CharacterData.vala
+++ b/gxml/libxml-CharacterData.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
 /* CharacterData.vala
  *
  * Copyright (C) 2011-2013  Richard Schwarting <aquarichy gmail com>
diff --git a/gxml/libxml-Document.vala b/gxml/libxml-Document.vala
index 183025b..943fe50 100644
--- a/gxml/libxml-Document.vala
+++ b/gxml/libxml-Document.vala
@@ -215,10 +215,10 @@ namespace GXml {
                                }
                        }
                        foreach (Xml.Node *freeable in to_free) {
-                               freeable->free ();
+                               delete freeable;
                        }
 
-                       this.xmldoc->free ();
+                       delete this.xmldoc;
                }
 
                /** Constructors */
@@ -307,7 +307,7 @@ namespace GXml {
                        doc = ctxt.read_file (file_path, null /* encoding */, 0 /* options */);
 
                        if (doc == null) {
-                               e = ctxt.get_last_error ();
+                               e = Xmlx.parser_context_get_last_error (ctxt);
                                GXml.warning (DomException.INVALID_DOC, "Could not load document from path: 
%s".printf (e->message));
                                throw new GXml.Error.PARSER (GXml.libxml2_error_to_string (e));
                        }
@@ -457,7 +457,7 @@ namespace GXml {
                        }
 
                        // uh oh
-                       e = Xml.Error.get_last_error ();
+                       e = Xmlx.get_last_error ();
                        if (e != null) {
                                errmsg += ".  " + libxml2_error_to_string (e);
                        }
@@ -531,7 +531,7 @@ namespace GXml {
                        }
 
                        // uh oh
-                       e = Xml.Error.get_last_error ();
+                       e = Xmlx.get_last_error ();
                        if (e != null) {
                                errmsg += ".  " + libxml2_error_to_string (e);
                        }
@@ -579,7 +579,7 @@ namespace GXml {
                        }
 
                        /* uh oh */
-                       e = Xml.Error.get_last_error ();
+                       e = Xmlx.get_last_error ();
                        if (e != null) {
                                errmsg += ".  " + libxml2_error_to_string (e);
                        }
@@ -862,7 +862,7 @@ namespace GXml {
                 */
                internal static bool check_invalid_characters (string name, string subject) {
                        /* TODO: use Xml.validate_name instead  */
-                       if (Xml.validate_name (name, 0) != 0) { // TODO: define validity
+                       if (Xmlx.validate_name (name, 0) != 0) { // TODO: define validity
                                GXml.warning (DomException.INVALID_CHARACTER, "Provided name '%s' for '%s' is 
not a valid XML name".printf (name, subject));
                                return false;
                        }
diff --git a/gxml/libxml-DocumentType.vala b/gxml/libxml-DocumentType.vala
index 2eb7794..2c20885 100644
--- a/gxml/libxml-DocumentType.vala
+++ b/gxml/libxml-DocumentType.vala
@@ -30,6 +30,7 @@ namespace GXml {
         * For more, see: [[http://www.w3.org/TR/DOM-Level-1/level-one-core.html#ID-412266927]]
         */
        public class DocumentType : xNode {
+               private Xml.Doc* doc;
                private Xml.Dtd *int_subset;
                private Xml.Dtd *ext_subset;
 
@@ -38,8 +39,9 @@ namespace GXml {
                        // TODO: for name, we want a real name of the doc type
                        base (NodeType.DOCUMENT_TYPE, doc);
 
-                       this.int_subset = int_subset;
-                       this.ext_subset = ext_subset;
+                       this.doc = doc.xmldoc;
+                       this.int_subset = this.doc->int_subset;
+                       this.ext_subset = this.doc->ext_subset;
                }
 
 
@@ -74,7 +76,7 @@ namespace GXml {
                                // TODO: need to create a HashTable<string,Entity> uniting these two
                                //       discard duplicates
                                // TODO: what type of hashtable is Xml.Dtd*'s entities?
-                               Xml.HashTable *table = this.int_subset->entities;
+                               Xml.HashTable *table = Xmlx.doc_get_dtd_entities (this.doc);
 
                                GLib.message ("About to scan for entities");
                                table->scan_full ((Xml.HashScannerFull)myScannerFull, null);
diff --git a/gxml/libxml-Error.vala b/gxml/libxml-Error.vala
index 68a3d1a..605636b 100644
--- a/gxml/libxml-Error.vala
+++ b/gxml/libxml-Error.vala
@@ -7,8 +7,8 @@ namespace GXml {
        // TODO: replace usage of this with GXml.get_last_error_msg
        internal static string libxml2_error_to_string (Xml.Error *e) {
                return "%s:%s:%d: %s:%d: %s".printf (
-                       e->level.to_string ().substring (8 /* skipping XML_ERR_ */),
-                       e->domain.to_string ().substring (9 /* skipping XML_FROM_ */),
+                       e->level.to_string ().replace ("XML_ERR_",""),
+                       e->domain.to_string ().replace ("XML_FROM_",""),
                        e->code, e->file == null ? "<io>" : e->file, e->line, e->message);
        }
 }
diff --git a/gxml/libxml-NamespaceAttrNodeList.vala b/gxml/libxml-NamespaceAttrNodeList.vala
index b4634ce..e394b1b 100644
--- a/gxml/libxml-NamespaceAttrNodeList.vala
+++ b/gxml/libxml-NamespaceAttrNodeList.vala
@@ -19,16 +19,161 @@
  * Authors:
  *      Daniel Espinosa <esodan gmail com>
  */
+using Gee;
+using Xml;
 // FIXME: Port this class as an implementation of Gee interfaces
-internal class GXml.NamespaceAttrNodeList : GXml.LinkedList {
-       internal NamespaceAttrNodeList (BackedNode root, xDocument owner) {
-               base (root);
-    if (root.node->ns_def == null) return;
-               Xml.Ns *cur = root.node->ns_def;
-               while (cur != null) {
-                       this.append_child (new NamespaceAttr (cur, owner));
-                       if (cur->next == null) break;
-                       cur = cur->next;
-               }
-       }
+internal abstract class GXml.AbstractNamespaceAttrNodeList : Object,
+  Gee.Traversable<Namespace>, Gee.Iterable<Namespace>, Gee.Collection<Namespace>
+{
+  protected unowned BackedNode node;
+
+  internal AbstractNamespaceAttrNodeList (BackedNode root) {
+    this.node = root;
+  }
+  public bool add (Namespace item) { return false; }
+  public void clear ()
+  {
+    foreach (Namespace ns in this) {
+      remove (ns);
+    }
+  }
+  public bool contains (Namespace nspace)
+  {
+    foreach (Namespace ns in this) {
+      if (nspace.uri == ns.uri && nspace.prefix == ns.prefix) return true;
+    }
+    return false;
+  }
+  public bool remove (Namespace ns) {  return false; }
+  public bool read_only { get { return true; } }
+  public Gee.Collection<Namespace> read_only_view
+  {
+    owned get { return new NamespaceAttrNodeList (this.node); }
+  }
+  public int size {
+    get {
+      int i = 0;
+      Xml.Ns* cur = node.node->ns;
+      while (cur != null) {
+        i++;
+        cur = cur->next;
+      }
+      return i;
+    }
+  }
+  public Gee.Iterator<Namespace> iterator () { return new Iterator (this); }
+
+  public new bool @foreach (Gee.ForallFunc<Namespace> f) {
+    return iterator ().foreach (f);
+  }
+  // Iterator
+  internal class Iterator : Object,
+    Gee.Traversable<Namespace>, Gee.Iterator<Namespace>
+  {
+    protected AbstractNamespaceAttrNodeList nl;
+    protected Xml.Ns* cur = null;
+    protected int i = -1;
+    public Iterator (AbstractNamespaceAttrNodeList nl)
+    {
+      this.nl = nl;
+    }
+    public new Namespace @get ()
+    {
+      return (Namespace) new NamespaceAttr (cur, nl.node.owner_document);
+    }
+    public bool has_next ()
+    {
+      if (cur == null) {
+        if (nl.node.node == null) return false;
+        if (nl.node.node->ns == null) return false;
+        return true;
+      }
+      if (cur->next == null) return false;
+      return true;
+    }
+               public bool next ()
+    {
+      if (cur == null) {
+        if (nl.node.node == null) return false;
+        if (nl.node.node->ns == null) return false;
+        cur = nl.node.node->ns;
+        i++;
+      }
+      if (cur->next == null) return false;
+      cur = cur->next;
+      return true;
+    }
+    public void remove () { return; }
+    public bool read_only { get { return true; } }
+    public bool valid
+    {
+      get {
+        if (cur == null) return false;
+        return true;
+      }
+    }
+    public new bool @foreach (Gee.ForallFunc<Namespace> f)
+    {
+      while (has_next ()) {
+        next ();
+        if (!f(@get())) return false;
+      }
+      return true;
+    }
+  }
+}
+
+internal class GXml.NamespaceAttrNodeList : AbstractNamespaceAttrNodeList,
+  Gee.List<Namespace>
+{
+  public NamespaceAttrNodeList (BackedNode root) {
+    base (root);
+  }
+  public new Namespace @get (int index)
+  {
+    Xml.Ns* cur = null;
+    if (this.node.node != null) {
+      if (node.node->ns != null) {
+        cur = node.node->ns;
+        int i = 0;
+        while (cur != null) {
+          if (index == i) break;
+          cur = cur->next;
+          i++;
+        }
+      }
+    }
+    return (Namespace) new NamespaceAttr (cur, node.owner_document);
+  }
+  public int index_of (Namespace item)
+  {
+    int i = -1;
+    Xml.Ns* cur = null;
+    if (node.node != null) {
+      cur = node.node->ns;
+      while (cur != null) {
+        i++;
+        if (item.uri == cur->href && item.prefix == cur->prefix) break;
+        cur = cur->next;
+      }
+    }
+    return i;
+  }
+  public void insert (int index, Namespace item) { return; }
+  public new Gee.ListIterator<Namespace> list_iterator () { return new Iterator (this); }
+  public Namespace remove_at (int index) { return get (index); }
+  public new void @set (int index, Namespace item) { return; }
+  public Gee.List<Namespace>? slice (int start, int stop) { return null; }
+  public new Gee.List<Namespace> read_only_view
+  {
+    owned get { return new NamespaceAttrNodeList (this.node); }
+  }
+  internal class Iterator : AbstractNamespaceAttrNodeList.Iterator,
+    Gee.ListIterator<Namespace>
+  {
+    public Iterator (NamespaceAttrNodeList l) { base (l); }
+    public void add (Namespace item) { return; }
+    public int index () { return i; }
+    public new void @set (Namespace item) { return; }
+  }
 }
diff --git a/gxml/libxml-Node.vala b/gxml/libxml-Node.vala
index e211c95..7c6a79f 100644
--- a/gxml/libxml-Node.vala
+++ b/gxml/libxml-Node.vala
@@ -84,7 +84,7 @@ namespace GXml {
                 *
                 * The caller must free this using { link GLib.Object.unref}.
                 */
-               public virtual NodeList? namespace_definitions {
+               public virtual Gee.List<Namespace>? namespace_definitions {
                        get {
                                return null;
                        }
@@ -502,7 +502,7 @@ namespace GXml {
                }
                
                // GXml.Node interface implementations
-               public virtual Gee.BidirList<GXml.Namespace> namespaces { get { return (Gee.BidirList) 
namespace_definitions; } }
+               public virtual Gee.List<GXml.Namespace> namespaces { get { return namespace_definitions; } }
                public virtual Gee.BidirList<GXml.Node> childs { get { return (BidirList<GXml.Node>) 
child_nodes; } }
                public virtual Gee.Map<string,GXml.Node> attrs { get { return (Map<string,GXml.Node>) 
_attributes; } }
                public virtual string name { get { return node_name; } }
diff --git a/gxml/xlibxml.c b/gxml/xlibxml.c
new file mode 100644
index 0000000..33f6f13
--- /dev/null
+++ b/gxml/xlibxml.c
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2015, Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Daniel Espinosa <esodan gmail com>
+ */
+
+#include<gxml/xlibxml.h>
+
+void* gxml_doc_get_intsubset_entities (xmlDoc *doc)
+{
+  return doc->intSubset->entities;
+}
+
+int gxml_validate_name (xmlChar* name, int space)
+{
+  return xmlValidateName (name, space);
+}
+
+xmlErrorPtr gxml_parser_context_get_last_error (void* ctx)
+{
+  return xmlCtxtGetLastError (ctx);
+}
+
+xmlErrorPtr gxml_get_last_error ()
+{
+  return xmlGetLastError ();
+}
diff --git a/gxml/xlibxml.h b/gxml/xlibxml.h
new file mode 100644
index 0000000..586bb38
--- /dev/null
+++ b/gxml/xlibxml.h
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2015, Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Daniel Espinosa <esodan gmail com>
+ */
+#ifndef __GXML_H_XLIBXML__
+#define __GXML_H_XLIBXML__
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+
+void*       gxml_doc_get_intsubset_entities    (xmlDoc *doc);
+int         gxml_validate_name                 (xmlChar* name, int space);
+xmlErrorPtr gxml_parser_context_get_last_error (void* ctx);
+xmlErrorPtr gxml_get_last_error                ();
+
+#endif
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index 394ed39..402e0d3 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -65,6 +65,7 @@ class DocumentTest : GXmlTest {
                Test.add_func ("/gxml/document/construct_from_path_error", () => {
                                xDocument doc;
                                try {
+                               GLib.message ("invalid file...");
                                        // file does not exist
                                        doc = new xDocument.from_path ("/tmp/asdfjlkansdlfjl");
                                        assert_not_reached ();
@@ -72,6 +73,7 @@ class DocumentTest : GXmlTest {
                                        assert (e is GXml.Error.PARSER);
                                }
                                test_error (DomException.INVALID_DOC);
+                               GLib.message ("invalid is directory...");
 
                                try {
                                        // file exists, but is not XML (it's a directory!)
@@ -81,7 +83,7 @@ class DocumentTest : GXmlTest {
                                        assert (e is GXml.Error.PARSER);
                                }
                                test_error (DomException.INVALID_DOC);
-
+                               GLib.message ("invalid xml...");
                                try {
                                        doc = new xDocument.from_path ("test_invalid.xml");
                                        assert_not_reached ();
diff --git a/test/ElementTest.vala b/test/ElementTest.vala
index e3d5d06..0c7e582 100644
--- a/test/ElementTest.vala
+++ b/test/ElementTest.vala
@@ -111,16 +111,16 @@ class ElementTest : GXmlTest  {
                                GXml.xNode root = doc.document_element;
                                GXml.xNode node = root.child_nodes.item (0);
 
-                               NodeList namespaces = node.namespace_definitions;
+                               Gee.List<Namespace> namespaces = node.namespace_definitions;
 
-                               assert (namespaces.length == 2);
+                               assert (namespaces.size == 2);
 
-                               assert (namespaces.item (0).namespace_prefix == "xmlns");
-                               assert (namespaces.item (0).node_name == "magic");
-                               assert (namespaces.item (0).node_value == "http://hogwarts.co.uk/magic";);
-                               assert (namespaces.item (1).namespace_prefix == "xmlns");
-                               assert (namespaces.item (1).node_name == "products");
-                               assert (namespaces.item (1).node_value == 
"http://diagonalley.co.uk/products";);
+                               assert (((NamespaceAttr)namespaces.get (0)).namespace_prefix == "xmlns");
+                               assert (namespaces.get (0).prefix == "magic");
+                               assert (namespaces.get (0).uri == "http://hogwarts.co.uk/magic";);
+                               assert (((NamespaceAttr)namespaces.get (1)).namespace_prefix == "xmlns");
+                               assert (namespaces.get (1).prefix == "products");
+                               assert (namespaces.get (1).uri == "http://diagonalley.co.uk/products";);
                                assert (node.local_name == "Potion");
                        });
                Test.add_func ("/gxml/element/attributes", () => {
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 584ee74..8da3fb9 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -277,14 +277,13 @@ class UnknownAttribute : ObjectModel
 
 public class NameSpace : SerializableObjectModel
 {
-  public NameSpace ()
+  public override bool set_namespace (GXml.Node node)
   {
-    serialize_set_namespace = "gxml|http://www.gnome.org/GXml";;
+    node.set_namespace ("http://www.gnome.org/GXml";, "gxml");
+    return true;
   }
   public override string to_string ()
   {
-    if (serialize_set_namespace != null)
-      return serialize_set_namespace;
     return "";
   }
 }
@@ -708,21 +707,21 @@ class SerializableObjectModelTest : GXmlTest
                          stdout.printf ("DOC: No root element");
                          assert_not_reached ();
                        }
-                       xElement element = doc.document_element;
-                       if (element.node_name != "Configuration") {
-                         stdout.printf (@"CONFIGURATION: Bad node name: $(element.node_name)");
+                       GXml.Element element = (GXml.Element) doc.root;
+                       if (element.name != "Configuration") {
+                         stdout.printf (@"CONFIGURATION: Bad node name: $(element.name)");
                          assert_not_reached ();
                        }
                        bool found = false;
-                       foreach (GXml.xNode n in element.namespace_definitions)
+                       foreach (GXml.Namespace n in element.namespaces)
                        {
-                         if (n.node_name == "om" && n.node_value == "http://www.gnome.org/gxml/0.4";)
+                         if (n.prefix == "om" && n.uri == "http://www.gnome.org/gxml/0.4";)
                            found = true;
                        }
                        if (!found) {
-                         stdout.printf (@"CONFIGURATION: No namespace found:");
-                         foreach (GXml.xNode n in element.namespace_definitions) {
-                           stdout.printf (@"CONFIGURATION: Defined Namespace: 
$(n.node_name):$(n.node_value)");
+                         stdout.printf (@"CONFIGURATION: No namespace found: size: 
$(element.namespaces.size)");
+                         foreach (GXml.Namespace n in element.namespaces) {
+                           stdout.printf (@"CONFIGURATION: Defined Namespace: $(n.prefix):$(n.uri)");
                          }
                          assert_not_reached ();
                        }
diff --git a/vapi/xlibxml-1.0.vapi b/vapi/xlibxml-1.0.vapi
new file mode 100644
index 0000000..bfa8929
--- /dev/null
+++ b/vapi/xlibxml-1.0.vapi
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2015, Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Daniel Espinosa <esodan gmail com>
+ */
+[CCode (cheader_filename = "gxml/xlibxml.h")]
+namespace Xmlx {
+  [CCode (cname = "gxml_doc_get_intsubset_entities", cheader_filename = "gxml/xlibxml.h")]
+  static Xml.HashTable doc_get_dtd_entities (Xml.Doc *doc);
+  [CCode (cname = "gxml_validate_name", cheader_filename = "gxml//xlibxml.h")]
+  static int validate_name (string name, int space);
+  [CCode (cname = "gxml_parser_context_get_last_error", cheader_filename = "gxml/xlibxml.h")]
+  static Xml.Error* parser_context_get_last_error (Xml.ParserCtxt ctx);
+  [CCode (cname = "gxml_get_last_error", cheader_filename = "gxml/xlibxml.h")]
+  static Xml.Error* get_last_error ();
+}


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