[gxml/gxml-0.18] Added default namespace and their namespaces



commit b489356480031a68b225cd8a86a700c278a55a50
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Feb 25 14:18:30 2020 -0600

    Added default namespace and their namespaces
    
    Looking for default namespaces 'xml' or 'xmlns'
    returns default URI http://www.w3.org/XML/1998/namespace
    and http://www.w3.org/2000/xmlns respectivaly.

 gxml/GomElement.vala | 24 +++++++++++++++++++++---
 gxml/XParser.vala    |  4 +++-
 2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index ec8d4a2..824f764 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -156,6 +156,13 @@ public class GXml.GomElement : GomNode,
   }
   // DomNode overrides
   public new string? lookup_prefix (string? nspace) {
+    if (nspace == "http://www.w3.org/XML/1998/namespace";
+        || nspace == "http://www.w3.org/XML/1998/namespace/";) {
+      return "xml";
+    } else if (nspace == "http://www.w3.org/2000/xmlns";
+        || nspace == "http://www.w3.org/2000/xmlns/"; ) {
+      return "xmlns";
+    }
     if (_namespace_uri == nspace)
       return _prefix;
     foreach (string k in _attributes.keys) {
@@ -184,6 +191,12 @@ public class GXml.GomElement : GomNode,
     return parent_node.lookup_prefix (nspace);
   }
   public new string? lookup_namespace_uri (string? prefix) {
+    if (prefix == "xmlns") {
+      return "http://www.w3.org/2000/xmlns";;
+    } else if (prefix == "xml") {
+      return "http://www.w3.org/XML/1998/namespace";;
+    }
+
     foreach (string k in attributes.keys) {
       if (!("xmlns" in k)) continue;
       var p = _attributes.get (k) as DomAttr;
@@ -413,9 +426,9 @@ public class GXml.GomElement : GomNode,
         p = s[0];
         n = s[1].down ();
         if (p == "xml")
-          ns = "http://www.w3.org/2000/xmlns/";;
+          ns = "http://www.w3.org/XML/1998/namespace";;
         if (p == "xmlns")
-          ns = _element.lookup_namespace_uri (n);
+          ns = "http://www.w3.org/2000/xmlns";;
         if (p != "xmlns" && p != "xml")
           ns =  _element.lookup_namespace_uri (p);
       }
@@ -510,6 +523,11 @@ public class GXml.GomElement : GomNode,
           && (node as DomAttr).namespace_uri != "http://www.w3.org/2000/xmlns/";
               && (node as DomAttr).namespace_uri != "http://www.w3.org/2000/xmlns";)
         throw new DomError.NAMESPACE_ERROR (_("Namespace attributes prefixed with xmlns should use a 
namespace uri http://www.w3.org/2000/xmlns";));
+
+      if ((node as DomAttr).prefix == "xml"
+          && (node as DomAttr).namespace_uri != "http://www.w3.org/XML/1998/namespace/";
+              && (node as DomAttr).namespace_uri != "http://www.w3.org/XML/1998/namespace";)
+        throw new DomError.NAMESPACE_ERROR (_("Namespace attributes prefixed with xml should use a namespace 
uri http://www.w3.org/XML/1998/namespace";));
       if ((node as DomAttr).prefix == ""
           || (node as DomAttr).prefix == null
           && (node as DomAttr).local_name != "xmlns") {
@@ -641,7 +659,7 @@ public class GXml.GomElement : GomNode,
     }
     if (namespace_uri == null && p == "")
        throw new DomError.NAMESPACE_ERROR (_("Invalid namespace. If prefix is null, namespace URI should not 
be null"));
-    if (p == "xml" && namespace_uri != "http://www.w3.org/2000/xmlns/"; && namespace_uri != 
"http://www.w3.org/2000/xmlns";)
+    if (p == "xml" && namespace_uri != "http://www.w3.org/XML/1998/namespace/"; && namespace_uri != 
"http://www.w3.org/XML/1998/namespace";)
        throw new DomError.NAMESPACE_ERROR (_("Invalid namespace. If prefix is xml, namespace URI should be 
http://www.w3.org/2000/xmlns";));
     if (p == "xmlns" && namespace_uri != "http://www.w3.org/2000/xmlns/";
             && namespace_uri != "http://www.w3.org/2000/xmlns";)
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index fdb7931..3b15347 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -350,8 +350,10 @@ public class GXml.XParser : Object, GXml.Parser {
           if (!processed) {
             if (prefix != null) {
               string nsuri = null;
+              if (prefix == "xmlns")
+                nsuri = "http://www.w3.org/2000/xmlns";;
               if (prefix == "xml")
-                nsuri = "http://www.w3.org/2000/xmlns/";;
+                nsuri = "http://www.w3.org/XML/1998/namespace";;
               else
                 nsuri = tr.lookup_namespace (prefix);
               element.set_attribute_ns (nsuri, prefix+":"+attrname, attrval);


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