[gxml] Added support to parse namespaces to TDocument.read_node()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added support to parse namespaces to TDocument.read_node()
- Date: Wed, 9 Mar 2016 19:12:23 +0000 (UTC)
commit 5ff529a01c18c32c15e811dcce70abe9229d82f3
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Mar 9 11:27:19 2016 -0600
Added support to parse namespaces to TDocument.read_node()
gxml/TDocument.vala | 26 ++++++++++++++++++++------
test/t-read-test.xml | 7 +++++--
2 files changed, 25 insertions(+), 8 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index 2a4be7a..30c18e7 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -417,7 +417,7 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
Xml.TextReader tr,
ReadTypeFunc? rntfunc = null) throws GLib.Error {
GXml.Node n = null;
- string prefix;
+ string prefix, nsuri;
ReadType rt = ReadType.CONTINUE;
if (rntfunc != null) rt = rntfunc (node, tr);
if (rt == ReadType.CONTINUE)
@@ -437,6 +437,13 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
node.children.add (n);
GLib.message ("ReadNode: next node:"+n.to_string ());
GLib.message ("ReadNode: next node attributes:"+(tr.has_attributes ()).to_string ());
+ prefix = tr.prefix ();
+ if (prefix != null) {
+ nsuri = tr.lookup_namespace (prefix);
+ if (nsuri != null) {
+ n.set_namespace (nsuri, prefix);
+ }
+ }
var c = tr.move_to_first_attribute ();
while (c == 1) {
if (tr.is_namespace_decl () == 1) {
@@ -444,22 +451,29 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
string nsp = tr.const_local_name ();
tr.read_attribute_value ();
if (tr.node_type () == Xml.ReaderType.TEXT) {
- string nuri = tr.read_string ();
- n.set_namespace (nuri,nsp);
+ nsuri = tr.read_string ();
+ n.set_namespace (nsuri,nsp);
}
} else {
var attrname = tr.const_local_name ();
+ prefix = tr.prefix ();
GLib.message ("Attribute: "+tr.const_local_name ());
tr.read_attribute_value ();
if (tr.node_type () == Xml.ReaderType.TEXT) {
var attrval = tr.read_string ();
GLib.message ("Attribute:"+attrname+" Value: "+attrval);
- (n as GXml.Element).set_attr (attrname, attrval);
+ if (prefix != null) {
+ nsuri = tr.lookup_namespace (prefix);
+ if (nsuri != null) {
+ GLib.message ("Setting a NS Attribute: "+prefix+":"+attrname);
+ (n as GXml.Element).set_ns_attr (new TNamespace (n.document, nsuri, prefix), attrname,
attrval);
+ }
+ } else
+ (n as GXml.Element).set_attr (attrname, attrval);
}
}
- c = tr.move_to_next_attribute (); // FIXME: Ns
+ c = tr.move_to_next_attribute ();
}
- // FIXME: Ns
while (read_node (n, tr, rntfunc) == ReadType.CONTINUE);
GLib.message ("Current Document: "+node.document.to_string ());
break;
diff --git a/test/t-read-test.xml b/test/t-read-test.xml
index bfd16c3..3c34f7e 100644
--- a/test/t-read-test.xml
+++ b/test/t-read-test.xml
@@ -1,8 +1,10 @@
<?xml version="1.0"?>
-<Sentences xmlns:gxml="http://wiki.gnome.org/GXml">
+<Sentences xmlns:gxml="http://wiki.gnome.org/GXml"
+ xmlns:b="http://book.org/schema">
<Sentence lang="en">I like the colour blue.</Sentence>
<Sentence lang="es">EspaƱol</Sentence>
- <Authors year="2016" collection="Back">
+ <Authors year="2016" collection="Back"
+ xmlns:auth="http://author.org">
<Author>
<Name>Fred</Name>
<Email>fweasley hogwarts co uk</Email>
@@ -12,4 +14,5 @@
<Email>gweasley hogwarts co uk</Email>
</Author>
</Authors>
+ <b:Book gxml:name="Thor"/>
</Sentences>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]