[gxml] Fixed GElement implementation of DomElement.tag_name



commit 5d76d8ace2ee9acffb816ee13300cd20c81ffb94
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Jul 20 12:40:28 2016 -0500

    Fixed GElement implementation of DomElement.tag_name
    
    * Re-arranged interface implementation and pre-requisite, because
      it matters and because the way it was makes valac to generate bad
      C code with no override of DomElement.tag_name property, making it
      to segfult

 gxml/DomElement.vala       |    4 ++--
 gxml/GXmlElement.vala      |   32 ++++++++++++++++++--------------
 test/DomGDocumentTest.vala |   10 ++++++++++
 3 files changed, 30 insertions(+), 16 deletions(-)
---
diff --git a/gxml/DomElement.vala b/gxml/DomElement.vala
index 991dbf8..f28da7b 100644
--- a/gxml/DomElement.vala
+++ b/gxml/DomElement.vala
@@ -22,9 +22,9 @@
 
 public interface GXml.DomElement : GLib.Object,
                   GXml.DomNode,
-                  GXml.DomParentNode,
+                  GXml.DomChildNode,
                   GXml.DomNonDocumentTypeChildNode,
-                  GXml.DomChildNode
+                  GXml.DomParentNode
 {
   /**
    * Returns default namespace's uri defined in node or first found.
diff --git a/gxml/GXmlElement.vala b/gxml/GXmlElement.vala
index fd71fcc..1dc603d 100644
--- a/gxml/GXmlElement.vala
+++ b/gxml/GXmlElement.vala
@@ -26,9 +26,8 @@ using Gee;
  * Class implemeting {@link GXml.Element} interface, not tied to libxml-2.0 library.
  */
 public class GXml.GElement : GXml.GNonDocumentChildNode,
-                            GXml.Element, GXml.DomParentNode,
-                            GXml.DomEventTarget,
-                            GXml.DomElement
+                            GXml.DomParentNode,
+                            GXml.DomElement, GXml.Element
 {
   public GElement (GDocument doc, Xml.Node *node) {
     _node = node;
@@ -120,10 +119,22 @@ public class GXml.GElement : GXml.GNonDocumentChildNode,
   }
   public string tag_name {
     owned get {
-      if (_node == null) return name;
-      if (_node->ns != null)
-          return _node->ns->prefix+":"+name;
-      return name;
+      if (_node == null) return "".dup ();
+      var ns = _node->ns_def;
+      var dns = ns;
+      while (ns != null) {
+        if (ns->prefix == null) dns = ns;
+        ns = ns->next;
+      }
+      if (dns != null) {
+        if (dns->href == "http://www.w3.org/1999/xhtml";)
+          return _node->name.up ().dup ();
+        if (dns->prefix == null)
+          return _node->name;
+        string qname = dns->prefix+":"+_node->name;
+        return qname.dup ();
+      }
+      return _node->name.dup ();
     }
   }
   public override string to_string () {
@@ -162,13 +173,6 @@ public class GXml.GElement : GXml.GNonDocumentChildNode,
     }
   }
   public string local_name { owned get { return name; } }
-  /*public string GXml.DomElement.tag_name {
-    get {
-      if (namespace != null)
-        return namespace.prefix+":"+name;
-      return name;
-    }
-  }*/
 
   public string? id {
     owned get {
diff --git a/test/DomGDocumentTest.vala b/test/DomGDocumentTest.vala
index d816371..4e52075 100644
--- a/test/DomGDocumentTest.vala
+++ b/test/DomGDocumentTest.vala
@@ -241,6 +241,12 @@ static const string HTMLDOC ="
                        assert (p.children[0].node_name == "p");
                        assert (!p.has_attribute ("id"));
                        assert (p.children[0].get_attribute ("class") == "black");
+                       // Checking for DomElement NS
+                       assert (ng2 is DomElement);
+                       assert (ng2.node_name == "OtherNode");
+                       assert (ng2.lookup_namespace_uri (null) == "http://live.gnome.org/GXml";);
+                       assert (ng2.lookup_prefix ("http://live.gnome.org/GXml";) == null);
+                       assert (ng2.tag_name == "OtherNode");
                        } catch (GLib.Error e) {
                                GLib.message ("Error: "+e.message);
                                assert_not_reached ();
@@ -276,6 +282,10 @@ static const string HTMLDOC ="
                        assert (n.attributes.get_named_item ("id") is DomNode);
                        assert (n.attributes.get_named_item ("id").node_name == "id");
                        assert (n.attributes.get_named_item ("id").node_value == "0y1");
+                       assert (n.node_name == "code");
+                       assert ((n as DomNode).lookup_namespace_uri ("gxml") == "http://live.gnome.org/GXml";);
+                       assert ((n as DomNode).lookup_prefix ("http://live.gnome.org/GXml";) == "gxml");
+                       assert (n.tag_name == "gxml:code");
                });
        }
 }


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