[Libguestfs] [PATCH v3 03/10] mllib: add Xml.parse_file helper

Cédric Bosdonnat cbosdonnat at suse.com
Fri Feb 10 15:05:58 UTC 2017


Provide a helper function rather than having callers read the
file and then parse the string.
---
 mllib/xml.ml  | 4 ++++
 mllib/xml.mli | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/mllib/xml.ml b/mllib/xml.ml
index e67245188..78e75b8f2 100644
--- a/mllib/xml.ml
+++ b/mllib/xml.ml
@@ -67,6 +67,10 @@ let parse_memory xml =
   Gc.finalise free_docptr docptr;
   docptr
 
+let parse_file file =
+  let xml = Common_utils.read_whole_file file in
+  parse_memory xml
+
 external _copy_doc : docptr -> recursive:bool -> docptr = "mllib_xml_copy_doc"
 let copy_doc docptr ~recursive =
   let copy = _copy_doc docptr ~recursive in
diff --git a/mllib/xml.mli b/mllib/xml.mli
index 9b2bc5c18..92d4977a2 100644
--- a/mllib/xml.mli
+++ b/mllib/xml.mli
@@ -33,6 +33,9 @@ val parse_memory : string -> doc
     For security reasons it actually calls xmlReadMemory with the
     [XML_PARSE_NONET] option set. *)
 
+val parse_file : string -> doc
+(** [parse_file path] parses the file pointed by [path].*)
+
 val copy_doc : doc -> recursive:bool -> doc
 (** http://xmlsoft.org/html/libxml-tree.html#xmlCopyDoc *)
 
-- 
2.11.0




More information about the Libguestfs mailing list