[gxml] StreamReader: can read empty elements
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] StreamReader: can read empty elements
- Date: Tue, 23 Jul 2019 18:47:36 +0000 (UTC)
commit c3169c080e9b11712a78468a650edeb120c20f7a
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Jul 22 14:28:13 2019 -0500
StreamReader: can read empty elements
gxml/StreamReader.vala | 7 +++++++
test/StreamReaderTest.vala | 17 ++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/gxml/StreamReader.vala b/gxml/StreamReader.vala
index 200366f..5df379b 100644
--- a/gxml/StreamReader.vala
+++ b/gxml/StreamReader.vala
@@ -155,6 +155,13 @@ public class GXml.StreamReader : GLib.Object {
if (is_space (buf[0])) {
break;
}
+ if (buf[0] == '/') {
+ string rest = stream.read_upto (">", -1, null, cancellable);
+ buf[0] = (char) stream.read_byte (cancellable);
+ var ee = document.create_element (name);
+ parent.append_child (ee);
+ return "<"+name+"/"+rest+(string) buf;
+ }
name += (string) buf;
buf[0] = (char) stream.read_byte (cancellable);
}
diff --git a/test/StreamReaderTest.vala b/test/StreamReaderTest.vala
index 5181b72..480398d 100644
--- a/test/StreamReaderTest.vala
+++ b/test/StreamReaderTest.vala
@@ -24,7 +24,7 @@ using GXml;
class GXmlTest {
public static int main (string[] args) {
Test.init (ref args);
- Test.add_func ("/gxml/stream-reader", () => {
+ Test.add_func ("/gxml/stream-reader/root", () => {
string str = """<root p1="a" p2="b" ><child>ContentChild</child></root>""";
var istream = new MemoryInputStream.from_data (str.data, null);
var sr = new StreamReader (istream);
@@ -39,6 +39,21 @@ class GXmlTest {
warning ("Error: %s", e.message);
}
});
+ Test.add_func ("/gxml/stream-reader/child", () => {
+ string str = """<root p1="a" p2="b" ><child k="p" y="9"><code/></child></root>""";
+ var istream = new MemoryInputStream.from_data (str.data, null);
+ var sr = new StreamReader (istream);
+ try {
+ var doc = sr.read ();
+ message (doc.write_string ());
+ message ((doc.document_element as GXml.Element).unparsed);
+ message ((doc.document_element.child_nodes.item (0) as
GXml.Element).unparsed);
+ assert ((doc.document_element as GXml.Element).unparsed == """<root p1="a"
p2="b" ></root>""");
+ assert ((doc.document_element.child_nodes.item(0) as GXml.Element).unparsed
== """<child k="p" y="9"><code/></child>""");
+ } catch (GLib.Error e) {
+ warning ("Error: %s", e.message);
+ }
+ });
Test.run ();
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]