[gxml/xpath: 1/8] Error.vala: add get_last_error_msg convenience function NamespaceAttr.vala: make Ns accessible inter
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/xpath: 1/8] Error.vala: add get_last_error_msg convenience function NamespaceAttr.vala: make Ns accessible inter
- Date: Tue, 15 Oct 2013 15:52:44 +0000 (UTC)
commit a5fee913124fb107e87dd51b82fe855c7283ea5a
Author: Adam Ples <ples adam gmail com>
Date: Mon Oct 14 05:24:28 2013 -0400
Error.vala: add get_last_error_msg convenience function
NamespaceAttr.vala: make Ns accessible internally, for XPath
Node.vala: add evaluate function for XPath
gxml/Error.vala | 14 ++++++++++++++
gxml/NamespaceAttr.vala | 2 +-
gxml/Node.vala | 22 ++++++++++++++++++++++
3 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/gxml/Error.vala b/gxml/Error.vala
index f0d6405..af367a8 100644
--- a/gxml/Error.vala
+++ b/gxml/Error.vala
@@ -3,6 +3,20 @@ namespace GXml {
PARSER, WRITER;
}
+ // TODO: rename
+ /**
+ * Returns error message for last registered error.
+ */
+ internal static string get_last_error_msg () {
+ Xml.Error* error = Xml.get_last_error ();
+
+ if (error == null)
+ return "No error reported by libxml2";
+ else
+ return libxml2_error_to_string (error);
+ }
+
+ // TODO: replace usage of this with xml_error_msg
internal static string libxml2_error_to_string (Xml.Error *e) {
return "%s:%s:%d: %s:%d: %s".printf (
e->level.to_string ().substring (8 /* skipping XML_ERR_ */),
diff --git a/gxml/NamespaceAttr.vala b/gxml/NamespaceAttr.vala
index 79b9f5a..8fe0ef9 100644
--- a/gxml/NamespaceAttr.vala
+++ b/gxml/NamespaceAttr.vala
@@ -32,7 +32,7 @@ namespace GXml {
*/
public class NamespaceAttr : Node {
/** Private properties */
- private Xml.Ns *node;
+ internal Xml.Ns *node; // XPATH:TODO: do they extend us?
/** Constructors */
internal NamespaceAttr (Xml.Ns *node, Document doc) {
diff --git a/gxml/Node.vala b/gxml/Node.vala
index 711eef1..67d2f90 100644
--- a/gxml/Node.vala
+++ b/gxml/Node.vala
@@ -492,5 +492,27 @@ namespace GXml {
public virtual string to_string (bool format = false, int level = 0) {
return "Node(%d:%s)".printf (this.node_type, this.node_name);
}
+
+ /*** XPath functions ***/
+
+ /* XPATH:TODO: should Node implement "XPathEvaluator" as an interface? No? */
+
+ /**
+ * Evaluates XPath expression in context of current DOM node (or Document).
+ *
+ * @param expr XPath expression
+ * @param nsr namespace resolver object (prefix -> URI mapping)
+ * @param res_type type to cast resulting value to
+ * @return XPath.Result object containing result type and value
+ * @throws DomError when node type is not supported as context of evaluation
+ * @throws XPath.Error when supplied with invalid XPath expression
+ */
+ public XPath.Result evaluate (string expr, XPath.NSResolver? nsr = null,
+ XPath.ResultType res_type = XPath.ResultType.ANY)
+ throws DomError, XPath.Error
+ {
+ var expression = new XPath.Expression (expr, nsr);
+ return expression.evaluate (this, res_type);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]