[gxml] XParser: Fixed writting just attribes no ns
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] XParser: Fixed writting just attribes no ns
- Date: Thu, 3 Nov 2016 19:32:34 +0000 (UTC)
commit 1268aa51bd9246bd695093c59e342d1ba139cc4d
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Nov 3 12:49:20 2016 -0600
XParser: Fixed writting just attribes no ns
If an attribute is prefixed, no namespace
definition is added to output.
gxml/XParser.vala | 21 ++++-----------------
test/GomDocumentTest.vala | 28 ++++++++++------------------
2 files changed, 14 insertions(+), 35 deletions(-)
---
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 4890fe9..f2acaaa 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -343,26 +343,13 @@ public class GXml.XParser : Object, GXml.Parser {
#endif
if ((node as DomElement).prefix != null || (node as DomElement).namespace_uri != null)
tw.start_element_ns ((node as DomElement).prefix, (node as DomElement).local_name, (node as
DomElement).node_name);
- else // Don't prefix. Using default namespace and prefix_default_ns = false
+ else
tw.start_element (node.node_name);
GLib.message ("Write down properties: size:"+(node as DomElement).attributes.size.to_string ());
foreach (string ak in (node as DomElement).attributes.keys) {
- var attr = (node as DomElement).attributes.get_named_item (ak);
- if (attr == null) {
- GLib.warning ("Attr key: "+ak+ "not found");
- continue;
- }
- if (attr.node_name != null) GLib.message ("Attribute name: "+attr.node_name);
-#if DEBUG
- GLib.message (@"Starting Element '$(node.node_name)': write attribute '$((attr as
DomAttr).local_name)'");
-#endif
- if ((attr as DomAttr).prefix != null)
- size += tw.write_attribute_ns ((attr as DomAttr).prefix,
- (attr as DomAttr).local_name,
- (attr as DomAttr).namespace_uri,
- attr.node_value);
- else
- size += tw.write_attribute (attr.node_name, attr.node_value);
+ string v = ((node as DomElement).attributes as HashMap<string,string>).get (ak);
+ size += tw.write_attribute (ak, v);
+ size += tw.end_attribute ();
if (size > 1500)
tw.flush ();
}
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index a152b1a..01393fb 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -134,24 +134,16 @@ class GomDocumentTest : GXmlTest {
var d = new GomDocument.from_file (rf);
assert (d != null);
assert (d.document_element != null);
- GLib.message ("File read: "+d.to_string ());
- assert (d.document_element.node_name == "Project");
- bool fname, fshordesc, fdescription, fhomepage;
- fname = fshordesc = fdescription = fhomepage = false;
- foreach (DomNode n in d.document_element.child_nodes) {
- if (n.node_name == "name") fname = true;
- if (n.node_name == "shortdesc") fshordesc = true;
- if (n.node_name == "description") fdescription = true;
- if (n.node_name == "homepage") fhomepage = true;
- }
- assert (fname);
- assert (fshordesc);
- assert (fdescription);
- assert (fhomepage);
- var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/xml.doap");
- d.write_file (f);
- assert (f.query_exists ());
- f.delete ();
+ string s = d.to_string ();
+ GLib.message ("File read: "+s);
+ assert ("""<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:gnome="http://api.gnome.org/doap-extensions#" xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns="http://usefulinc.com/ns/doap#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">"""
+ in s);
+ assert ("<name xml:lang=\"en\">GXml</name>" in s);
+ assert ("<shortdesc xml:lang=\"en\">GObject XML and Serialization
API</shortdesc>"
+ in s);
+ assert ("<homepage rdf:resource=\"https://wiki.gnome.org/GXml\"/>" in s);
+ assert ("<foaf:Person>" in s);
+ assert ("<foaf:name>Daniel Espinosa</foaf:name>" in s);
} catch (GLib.Error e) {
GLib.message ("Error: "+e.message);
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]