[gxml] Fixed lookup_namespace_uri(). More XML namespace fixes
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed lookup_namespace_uri(). More XML namespace fixes
- Date: Sun, 22 Oct 2017 01:59:13 +0000 (UTC)
commit a561c2b9d7008b538a0078810b53bf3389702b55
Author: Daniel Espinosa <esodan gmail com>
Date: Sat Oct 21 20:54:22 2017 -0500
Fixed lookup_namespace_uri(). More XML namespace fixes
Fixed lookup paren namespace definitions.
Default URI namespace denitions fixes.
gxml/GomElement.vala | 25 ++++++-------------------
test/GomDocumentTest.vala | 12 ++++++++----
test/GomElementTest.vala | 24 ++++++++++++++++--------
3 files changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 438d1cc..e2bc8d6 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -184,26 +184,18 @@ public class GXml.GomElement : GomNode,
return parent_node.lookup_prefix (nspace);
}
public new string? lookup_namespace_uri (string? prefix) {
- if (_namespace_uri != null && _prefix == prefix)
- return namespace_uri;
- string s = "";
- if (prefix != null) s = prefix;
foreach (string k in attributes.keys) {
if (!("xmlns" in k)) continue;
-#if DEBUG
- GLib.message ("Attribute: "+k);
-#endif
- string nsp = null;
+ string nsp = _attributes.get (k);
+ if (prefix == null && k == "xmlns") return nsp;
if (":" in k) {
string[] sa = k.split (":");
- if (sa.length > 2) {
+ if (sa.length != 2) {
GLib.warning (_("Invalid attribute name in element's attributes list"));
return null;
}
- nsp = sa[1];
+ if (prefix == sa[1]) return nsp;
}
- if (nsp != prefix) continue;
- return _attributes.get (k);
}
if (parent_node == null) return null;
return parent_node.lookup_namespace_uri (prefix);
@@ -541,19 +533,14 @@ public class GXml.GomElement : GomNode,
}
public DomNamedNodeMap attributes { owned get { return (DomNamedNodeMap) _attributes; } }
public string? get_attribute (string name) {
-#if DEBUG
- message ("Searching attribute: "+name);
-#endif
string s = (this as GomObject).get_attribute (name);
-#if DEBUG
- message ("Found as GomObject Property?: "+(s != null).to_string ());
-#endif
if (s != null) return s;
return _attributes.get (name);
}
public string? get_attribute_ns (string? namespace_uri, string local_name) {
string nsp = null;
- if (namespace_uri == "http://www.w3.org/2000/xmlns/"
+ if ((namespace_uri == "http://www.w3.org/2000/xmlns/"
+ || namespace_uri == "http://www.w3.org/2000/xmlns")
&& local_name != "xmlns")
nsp = "xmlns";
else
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index ec5d7c0..f4ee855 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -413,11 +413,17 @@ class GomDocumentTest : GXmlTest {
Test.add_func ("/gxml/gom-document/namespace/create", () => {
try {
DomDocument doc = new GomDocument.from_string
("<document_element><child/></document_element>");
+
+ assert (doc.document_element != null);
+ assert (doc.document_element.namespace_uri == null);
+ assert (doc.document_element.prefix == null);
+ assert (doc.document_element.lookup_namespace_uri (null) == null);
doc.document_element.set_attribute_ns ("http://www.w3.org/2000/xmlns/",
"xmlns","http://www.gnome.org/GXml");
assert (doc.document_element != null);
assert (doc.document_element.namespace_uri == null);
assert (doc.document_element.prefix == null);
+ assert (doc.document_element.lookup_namespace_uri (null) ==
"http://www.gnome.org/GXml");
assert (doc.document_element.child_nodes != null);
assert (doc.document_element.child_nodes.size == 1);
var c = doc.document_element.child_nodes[0] as DomElement;
@@ -431,10 +437,8 @@ class GomDocumentTest : GXmlTest {
.get_attribute_ns
("http://www.gnome.org/GXml2", "prop");
assert (p != null);
assert (p == "val");
- assert (doc.document_element.lookup_namespace_uri (null) != null);
-#if DEBUG
- GLib.message ("NS default: "+doc.document_element.lookup_namespace_uri
(null));
-#endif
+ message ((doc as GomDocument).write_string ());
+ assert (doc.document_element.lookup_namespace_uri (null) ==
"http://www.gnome.org/GXml");
assert (c.prefix == null);
assert (c.namespace_uri == null);
assert (c.lookup_namespace_uri (null) == "http://www.gnome.org/GXml");
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index a231741..c71d9b9 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -47,11 +47,6 @@ class GomElementTest : GXmlTest {
assert ((node as DomElement).prefix == "magic");
assert ((node as DomElement).attributes.size == 2);
GLib.message ("Attributes: "+(node as DomElement).attributes.size.to_string
());
- /*foreach (string k in (node as DomElement).attributes.keys) {
- string v = (node as DomElement).get_attribute (k);
- if (v == null) v = "NULL";
- GLib.message ("Attribute: "+k+"="+v);
- }*/
assert ((node as DomElement).get_attribute ("xmlns:magic") ==
"http://hogwarts.co.uk/magic");
assert ((node as DomElement).get_attribute_ns
("http://www.w3.org/2000/xmlns/", "magic") == "http://hogwarts.co.uk/magic");
assert ((node as DomElement).get_attribute ("xmlns:products") ==
"http://diagonalley.co.uk/products");
@@ -168,9 +163,6 @@ class GomElementTest : GXmlTest {
assert ("id=\"idnode\"" in elem.write_string ());
assert (elem.id == "idnode");
try {
-#if DEBUG
- message ("Documento:"+parser.write_string ());
-#endif
elem.set_attribute_ns ("http://www.gnome.org/GXml",
"gxml2:xola","Mexico");
assert_not_reached ();
} catch (GLib.Error e) {
@@ -179,6 +171,22 @@ class GomElementTest : GXmlTest {
assert (elem != null);
assert (elem.attributes != null);
assert (elem.attributes.size == 2);
+ var n = doc.create_element ("node");
+ elem.append_child (n);
+ var child = doc.create_element ("child");
+ n.append_child (child);
+ elem.set_attribute_ns
("http://www.w3.org/2000/xmlns","xmlns:xtest","http://www.w3c.org/test");
+ assert (elem.lookup_prefix ("http://www.w3c.org/test") == "xtest");
+ assert (n.lookup_prefix ("http://www.w3c.org/test") == "xtest");
+ assert (child.lookup_prefix ("http://www.w3c.org/test") == "xtest");
+ assert (elem.lookup_namespace_uri ("xtest") == "http://www.w3c.org/test");
+ assert (n.lookup_namespace_uri ("xtest") == "http://www.w3c.org/test");
+ assert (child.lookup_namespace_uri ("xtest") == "http://www.w3c.org/test");
+ message ((elem as GomElement).write_string ());
+ child.set_attribute_ns ("http://www.w3c.org/test","xtest:val","Value");
+ assert (elem.get_attribute_ns ("http://www.w3.org/2000/xmlns/","xtest") ==
"http://www.w3c.org/test");
+ assert (elem.get_attribute_ns ("http://www.w3.org/2000/xmlns","xtest") ==
"http://www.w3c.org/test");
+ assert (child.get_attribute_ns ("http://www.w3c.org/test","val") == "Value");
} catch (GLib.Error e) {
GLib.message (e.message);
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]