[gxml] Fixed parse all attributes for TDocument.read_node()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed parse all attributes for TDocument.read_node()
- Date: Wed, 9 Mar 2016 19:12:28 +0000 (UTC)
commit 4faf81383e78373d27fd7177399317d7c89e6195
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Mar 9 12:31:58 2016 -0600
Fixed parse all attributes for TDocument.read_node()
gxml/TDocument.vala | 11 ++++++++---
test/TDocumentTest.vala | 9 +++++++--
test/t-read-test.xml | 3 ++-
3 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index 30c18e7..966c95f 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -442,10 +442,15 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
nsuri = tr.lookup_namespace (prefix);
if (nsuri != null) {
n.set_namespace (nsuri, prefix);
+ GLib.message ("Number of NS in node: "+n.namespaces.size.to_string ());
}
}
- var c = tr.move_to_first_attribute ();
- while (c == 1) {
+ var nattr = tr.attribute_count ();
+ GLib.message ("Number of Attributes:"+nattr.to_string ());
+ for (int i = 0; i < nattr; i++) {
+ GLib.message ("Current Attribute: "+i.to_string ());
+ var c = tr.move_to_attribute_no (i);
+ if (c != 1) GLib.message ("Fail to move to attribute number: "+i.to_string ());
if (tr.is_namespace_decl () == 1) {
GLib.message ("Is Namespace Declaration...");
string nsp = tr.const_local_name ();
@@ -453,6 +458,7 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
if (tr.node_type () == Xml.ReaderType.TEXT) {
nsuri = tr.read_string ();
n.set_namespace (nsuri,nsp);
+ GLib.message ("Number of NS in node: "+n.namespaces.size.to_string ());
}
} else {
var attrname = tr.const_local_name ();
@@ -472,7 +478,6 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
(n as GXml.Element).set_attr (attrname, attrval);
}
}
- c = tr.move_to_next_attribute ();
}
while (read_node (n, tr, rntfunc) == ReadType.CONTINUE);
GLib.message ("Current Document: "+node.document.to_string ());
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
index a6e2c81..e68ad22 100644
--- a/test/TDocumentTest.vala
+++ b/test/TDocumentTest.vala
@@ -435,7 +435,9 @@ class TDocumentTest : GXmlTest {
GLib.message ("Doc:"+d.to_string ());
assert (d.root != null);
assert (d.root.name == "Sentences");
- assert (d.root.children.size == 3);
+ assert (d.root.attrs["audience"] != null);
+ assert (d.root.attrs["audience"].value == "All");
+ assert (d.root.children.size == 4);
var s1 = d.root.children[0];
assert (s1 != null);
assert (s1.name == "Sentence");
@@ -460,6 +462,9 @@ class TDocumentTest : GXmlTest {
var p3 = s3.attrs["year"];
assert (p3 != null);
assert (p3.value == "2016");
+ var p31 = s3.attrs["collection"];
+ assert (p31 != null);
+ assert (p31.value == "Back");
assert (s3.children.size == 2);
assert (s3.children[0] is GXml.Element);
assert (s3.children[0].name == "Author");
@@ -498,7 +503,7 @@ class TDocumentTest : GXmlTest {
GLib.message ("Doc:"+d.to_string ());
assert (d.root != null);
assert (d.root.name == "Sentences");
- assert (d.root.namespaces.size == 1);
+ assert (d.root.namespaces.size == 2);
} catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
});
}
diff --git a/test/t-read-test.xml b/test/t-read-test.xml
index 3c34f7e..cae6ece 100644
--- a/test/t-read-test.xml
+++ b/test/t-read-test.xml
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<Sentences xmlns:gxml="http://wiki.gnome.org/GXml"
- xmlns:b="http://book.org/schema">
+ xmlns:b="http://book.org/schema"
+ audience="All">
<Sentence lang="en">I like the colour blue.</Sentence>
<Sentence lang="es">EspaƱol</Sentence>
<Authors year="2016" collection="Back"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]