[gxml] XParser: Fixes on xml prefix parsing and write



commit 30f0aadee2dda218acbeabfe9abf1b4677276bd9
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Nov 2 22:11:40 2016 -0600

    XParser: Fixes on xml prefix parsing and write

 gxml/GomElement.vala      |    2 +-
 gxml/Parser.vala          |    2 --
 gxml/XParser.vala         |    9 +++++++--
 test/GomDocumentTest.vala |    2 +-
 4 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 83843eb..1cb79c9 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -399,7 +399,7 @@ public class GXml.GomElement : GomNode,
        throw new DomError.NAMESPACE_ERROR (_("Invalid namespace. If attribute's prefix is xmlns name space 
uri shoud be http://www.w3.org/2000/xmlns/";));
     if (p == "" && n == "xmlns" && namespace_uri != "http://www.w3.org/2000/xmlns/";)
        throw new DomError.NAMESPACE_ERROR (_("Invalid namespace. If attribute's name is xmlns name space uri 
shoud be http://www.w3.org/2000/xmlns/";));
-    if (p == "" && n != "xmlns")
+    if (p == "" && n != "xmlns" && n != "xml")
       throw new DomError.NAMESPACE_ERROR (_("Invalid attribute name. No prefixed attributes should use xmlns 
name"));
     // Check if a namespace is set
     if (_prefix == null && _namespace_uri == null) {
diff --git a/gxml/Parser.vala b/gxml/Parser.vala
index aedf528..fc968d8 100644
--- a/gxml/Parser.vala
+++ b/gxml/Parser.vala
@@ -50,8 +50,6 @@ public interface GXml.Parser : Object {
   public virtual void write_file (GLib.File file,
                             GLib.Cancellable? cancellable)
                             throws GLib.Error {
-    if (!file.query_exists ())
-      throw new GXml.ParserError.INVALID_FILE_ERROR (_("File doesn't exist"));
     var ostream = file.replace (null, backup,
                             GLib.FileCreateFlags.NONE, cancellable);
     write_stream (ostream, cancellable);
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 9d44a75..4890fe9 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -163,9 +163,10 @@ public class GXml.XParser : Object, GXml.Parser {
           if (tr.node_type () == Xml.ReaderType.TEXT) {
             string ansuri = tr.read_string ();
             GLib.message ("Read: "+aprefix+":"+nsp+"="+ansuri);
-            string ansp = "";
+            string ansp = nsp;
             if (nsp != "xmlns")
               ansp = aprefix+":"+nsp;
+            GLib.message ("To append: "+ansp+"="+ansuri);
             (n as DomElement).set_attribute_ns ("http://www.w3.org/2000/xmlns/";,
                                                  ansp, ansuri);
           }
@@ -182,7 +183,11 @@ public class GXml.XParser : Object, GXml.Parser {
             GLib.message ("Attribute:"+attrname+" Value: "+attrval);
 #endif
             if (prefix != null) {
-              nsuri = tr.lookup_namespace (prefix);
+              GLib.message ("Prefix found: "+prefix);
+              if (prefix == "xml")
+                nsuri = "http://www.w3.org/2000/xmlns/";;
+              else
+                nsuri = tr.lookup_namespace (prefix);
               (n as DomElement).set_attribute_ns (nsuri, prefix+":"+attrname, attrval);
             } else
               (n as DomElement).set_attribute (attrname, attrval);
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index a4a05a6..3b29639 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -187,7 +187,7 @@ class GomDocumentTest : GXmlTest {
                                        assert (f.query_exists ());
                                        f.delete ();
                                } catch (GLib.Error e) {
-                                       Test.message ("%s", e.message);
+                                       GLib.message ("%s", e.message);
                                        assert_not_reached ();
                                }
                        });


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