[gxml] Fixed TElement attributes with namespaces



commit e87ac2aa82de67dfc7abe3b9a749a49cc7333b11
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Mar 23 17:00:36 2016 -0600

    Fixed TElement attributes with namespaces
    
    * TElement attributes with namespaces are stored using prefix:name
      secuence on Hash Table, to get it from attrs use that convention
    * Added test cases for this

 NEWS                    |    6 ++++++
 configure.ac            |    2 +-
 gxml/TElement.vala      |    2 +-
 test/TDocumentTest.vala |   28 ++++++++++++++++++++++++++--
 test/TElementTest.vala  |   31 ++++++++++++++++++++++++++++++-
 5 files changed, 64 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index 3299080..96fc18c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,10 @@
 ===============
+Version 0.9.91
+===============
+
+* New TDocument.from_stream(), .from_string and .from_uri() methods
+
+===============
 Version 0.9.90
 ===============
 
diff --git a/configure.ac b/configure.ac
index bb5e8c9..58af991 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@
 # Release Version
 m4_define([project_major_version], [0])
 m4_define([project_minor_version], [9])
-m4_define([project_micro_version], [90])
+m4_define([project_micro_version], [91])
 m4_define([project_nano_version], [0])
 
 # LT_VERSION
diff --git a/gxml/TElement.vala b/gxml/TElement.vala
index 240337e..e8e2966 100644
--- a/gxml/TElement.vala
+++ b/gxml/TElement.vala
@@ -84,7 +84,7 @@ public class GXml.TElement : GXml.TNode, GXml.Element
     var att = new TAttribute (document, name, value);
     att.set_namespace (ns.uri, ns.prefix);
     att.set_parent (this);
-    attrs.set (name, att);
+    attrs.set (ns.prefix+":"+name, att);
   }
   public void remove_attr (string name) {
     if (attrs.has_key (name)) attrs.unset (name);
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
index 2c452de..8549be2 100644
--- a/test/TDocumentTest.vala
+++ b/test/TDocumentTest.vala
@@ -409,10 +409,11 @@ class TDocumentTest : GXmlTest {
                                        Test.message ("ROOT: "+doc.to_string ());
                                        string[] str = doc.to_string ().split("\n");
                                        assert (str[1] == "<root 
xmlns:gxml=\"http://www.gnome.org/GXml\";><gxml2:child xmlns:gxml2=\"http://www.gnome.org/GXml2\"/></root>");
+                                       assert (doc.namespaces[0].prefix == "gxml");
                                        (c as Element).set_ns_attr (doc.namespaces[0], "prop", "Ten");
                                        Test.message ("ROOT: "+doc.root.to_string ());
                                        assert (c.attrs.size == 1);
-                                       var pt = c.attrs.get ("prop");
+                                       var pt = c.attrs.get ("gxml:prop");
                                        assert (pt != null);
                                        var pt2 = (c as Element).get_ns_attr ("prop", doc.namespaces[0].uri);
                                        str = doc.to_string ().split("\n");
@@ -529,7 +530,7 @@ class TDocumentTest : GXmlTest {
                                assert (b.namespaces.size == 1);
                                assert (b.namespaces[0].prefix == "b");
                                assert (b.namespaces[0].uri == "http://book.org/schema";);
-                               var bp = b.attrs["name"];
+                               var bp = b.attrs["gxml:name"];
                                assert (bp != null);
                                assert (bp.name == "name");
                                assert (bp.namespaces.size == 1);
@@ -709,5 +710,28 @@ class TDocumentTest : GXmlTest {
                                assert (d.root.children[1].children[0].children[0].value == "COMMUNICATIONS");
                        } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
                });
+               Test.add_func ("/gxml/t-document/read/string/attrs", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument.from_string ("<root 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";><child v=\"1\" xsi:v=\"VType\">TEXT</child><doc 
year=\"2016\"><name>COMMUNICATIONS</name></doc></root>");
+                               assert (d.root != null);
+                               assert (d.root.name == "root");
+                               assert (d.root.children[0] != null);
+                               assert (d.root.children[0].name == "child");
+                               GLib.message ("child attri: "+(d.root.children[0].attrs.size).to_string ());
+                               assert (d.root.children[0].attrs.size == 2);
+                               assert (d.root.children[0].attrs["v"] != null);
+                               assert (d.root.children[0].children[0] is GXml.Text);
+                               assert (d.root.children[0].children[0].value == "TEXT");
+                               assert (d.root.children[1] != null);
+                               assert (d.root.children[1].name == "doc");
+                               assert (d.root.children[1].attrs["year"].value == "2016");
+                               assert (d.root.children[1].children[0] != null);
+                               assert (d.root.children[1].children[0].name == "name");
+                               assert (d.root.children[1].children[0].children[0] is GXml.Text);
+                               assert (d.root.children[1].children[0].children[0].value == "COMMUNICATIONS");
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
        }
 }
diff --git a/test/TElementTest.vala b/test/TElementTest.vala
index e48d5fa..df5263e 100644
--- a/test/TElementTest.vala
+++ b/test/TElementTest.vala
@@ -528,7 +528,7 @@ class TElementTest : GXmlTest {
                        assert ("</gxml:child>" in str);
                        } catch { assert_not_reached (); }
                });
-               Test.add_func ("/gxml/t-element/attr-namespace", () => {
+               Test.add_func ("/gxml/t-element/attr-namespace/default", () => {
                        try {
                        var d = new TDocument ();
                        var r = d.create_element ("root");
@@ -555,6 +555,35 @@ class TElementTest : GXmlTest {
                        assert ("</root>" in str);
                        } catch { assert_not_reached (); }
                });
+               Test.add_func ("/gxml/t-element/attr-namespace/same-name", () => {
+                       try {
+                       var d = new TDocument ();
+                       var r = d.create_element ("root");
+                       d.children.add (r);
+                       // Default NS
+                       r.set_namespace ("http://git.gnome.org/browse/gxml";, "gxml");
+                       var ns = new TNamespace (d, "http://books.net";, "book");
+                       r.set_namespace (ns.uri, ns.prefix);
+                       var c = d.create_element ("child") as Element;
+                       r.children.add (c);
+                       c.set_attr ("source","http://books.net/sources/1";);
+                       assert (c.attrs.size == 1);
+                       c.set_ns_attr (ns, "source", "The History 2");
+                       assert (c.attrs.size == 2);
+                       var nsa = c.get_ns_attr ("source", "http://books.net";);
+                       assert (nsa != null);
+                       assert (nsa.value == "The History 2");
+                       var nsat = c.attrs.get ("book:source");
+                       assert (nsat != null);
+                       assert (nsat.value == "The History 2");
+                       var a = c.attrs.get ("source");
+                       assert (a != null);
+                       assert (a.value == "http://books.net/sources/1";);
+//#if DEBUG
+                       GLib.message (@"$d");
+//#endif
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/t-element/parent", () => {
                        var doc = new TDocument ();
                        var e = doc.create_element ("root");


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