[gxml] Document.vala: add GXml.Error to Document.from_path, use Xml.ParserCtxt.read_file instead of Xml.Par



commit 25cbe6beba12b8a8a2d9bc7522f014808e6c40b0
Author: Richard Schwarting <aquarichy gmail com>
Date:   Wed Oct 2 10:07:07 2013 -0400

    Document.vala: add GXml.Error to Document.from_path, use Xml.ParserCtxt.read_file instead of 
Xml.Parser.parse_file, for error-handling

 gxml/Document.vala |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gxml/Document.vala b/gxml/Document.vala
index 71d8c35..760401f 100644
--- a/gxml/Document.vala
+++ b/gxml/Document.vala
@@ -310,10 +310,15 @@ namespace GXml {
                /**
                 * Creates a Document from the file at file_path.
                 */
-               public Document.from_path (string file_path) {
-                       // TODO: might want to check that the file_path exists
-                       // consider using Xml.Parser.read_file
-                       Xml.Doc *doc = Xml.Parser.parse_file (file_path);
+               public Document.from_path (string file_path) throws GXml.Error {
+                       Xml.ParserCtxt ctxt = new Xml.ParserCtxt ();
+                       Xml.Doc *doc = ctxt.read_file (file_path, null /* encoding */, 0 /* options */);
+
+                       if (doc == null) {
+                               Xml.Error *e = ctxt.get_last_error ();
+                               throw new GXml.Error.PARSER (GXml.libxml2_error_to_string (e));
+                       }
+
                        this.from_libxml2 (doc);
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]