[gxml] XParser: write element defuault xmlns
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] XParser: write element defuault xmlns
- Date: Thu, 3 Nov 2016 19:32:44 +0000 (UTC)
commit f85f1cf026826b37138bdaf9e62b963f0230abd7
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Nov 3 13:14:44 2016 -0600
XParser: write element defuault xmlns
If element has a namespace defined but no prefix
parser adds its namespace definition
gxml/GomDocument.vala | 2 +-
gxml/XParser.vala | 7 +++++++
test/GomDocumentTest.vala | 15 +++++++++++++++
3 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 8f36b00..a0c0c4b 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -113,7 +113,7 @@ public class GXml.GomDocument : GomNode,
public DomElement create_element_ns (string? namespace_uri, string qualified_name) throws GLib.Error
{
string n = "";
- string nsp = "";
+ string nsp = null;
if (":" in qualified_name) {
var s = qualified_name.split (":");
if (s.length != 2)
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 95e8253..737798b 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -346,6 +346,13 @@ public class GXml.XParser : Object, GXml.Parser {
string name = (node as DomElement).prefix
+ ":" + (node as DomElement).local_name;
tw.start_element (name);
+ }
+ if ((node as DomElement).prefix == null
+ && (node as DomElement).namespace_uri != null) {
+ GLib.message ("Writting namespace definition for node");
+ tw.start_element_ns (null,
+ (node as DomElement).local_name,
+ (node as DomElement).namespace_uri);
} else
tw.start_element (node.node_name);
GLib.message ("Write down properties: size:"+(node as DomElement).attributes.size.to_string ());
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index 01393fb..5b66b77 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -149,6 +149,21 @@ class GomDocumentTest : GXmlTest {
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/gom-document/namespace/write", () => {
+ try {
+ var doc = new GomDocument ();
+ var r = doc.create_element_ns ("http://live.gnome.org/GXml","root");
+ doc.append_child (r);
+ assert (r.prefix == null);
+ assert (r.namespace_uri == "http://live.gnome.org/GXml");
+ string s = doc.to_string ();
+ GLib.message (@"DOC: "+s);
+ assert ("<root xmlns=\"http://live.gnome.org/GXml\"/>" in s);
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/gom-document/construct_from_stream_error", () => {
File fin;
InputStream instream;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]