[gxml: 6/7] GomObject: Added initial support delayed parsing
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml: 6/7] GomObject: Added initial support delayed parsing
- Date: Sun, 9 Apr 2017 03:33:01 +0000 (UTC)
commit fc695ff25e4b70108b6d1f59f58109b54f37390c
Author: Daniel Espinosa <esodan gmail com>
Date: Sat Apr 8 19:39:51 2017 -0500
GomObject: Added initial support delayed parsing
gxml/GomElement.vala | 3 +++
gxml/GomObject.vala | 22 ++++++++++++++++++++++
gxml/XParser.vala | 6 ++++--
3 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 82b3b81..f9a1404 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -632,6 +632,9 @@ public class GXml.GomElement : GomNode,
}
return l;
}
+ // GomObject
+ public bool parse_children { get; set; default = true; }
+ public string unparsed { get; set; }
}
diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala
index 7a0736e..4658a6b 100644
--- a/gxml/GomObject.vala
+++ b/gxml/GomObject.vala
@@ -35,6 +35,28 @@ public interface GXml.GomObject : GLib.Object,
DomNode,
DomElement {
/**
+ * Controls if children should be parsed or delayed
+ */
+ public abstract bool parse_children { get; set; default = true; }
+ /**
+ * Holds unparsed text for this {@link GomElement}.
+ *
+ * If {@link parse_children} is true this will hold a string with all childrens
+ * for this {@link GomElement}. It is set to null if {@link parse_children} is false
+ * and {@link read_children} is called.
+ */
+ public abstract string unparsed { get; set; }
+ /**
+ * Reads all children stored in {@link unparsed} string.
+ *
+ * After this method is called, {@link unparsed} is freed.
+ */
+ public virtual void read_children () throws GLib.Error {
+ if (unparsed != null);
+ (this as GomElement).read_from_string (unparsed);
+ unparsed = null;
+ }
+ /**
* Returns a list with all properties' nick with "::" prefix. Nick name,
* with "::" prefix will be used on serialization to an attribute's name.
*/
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 466751a..189ba90 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -139,8 +139,10 @@ public class GXml.XParser : Object, GXml.Parser {
#endif
if (current_is_element () && (node is DomDocument))
read_child_element (node);
- else
- read_child_nodes (node);
+ else {
+ if ((node as GomObject).parse_children)
+ read_child_nodes (node);
+ }
}
/**
* Use parser to go to next parsed node.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]