[Pkg-libvirt-commits] [libguestfs] 163/266: v2v: DOM: Add XML comments (<!-- .. -->) to the model.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit d629b5252bbc26a5ffa88e235f6090f260bd436b
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Aug 21 23:24:39 2014 +0100

    v2v: DOM: Add XML comments (<!-- .. -->) to the model.
    
    This allows us to insert comments into the output libvirt XML or OVF.
---
 v2v/DOM.ml            | 10 +++++++++-
 v2v/DOM.mli           |  1 +
 v2v/output_RHEV.ml    |  2 +-
 v2v/output_libvirt.ml |  4 ++--
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/v2v/DOM.ml b/v2v/DOM.ml
index 0daf364..881400a 100644
--- a/v2v/DOM.ml
+++ b/v2v/DOM.ml
@@ -25,6 +25,7 @@ open Printf
 
 type node =
   | PCData of string
+  | Comment of string
   | Element of element
 and element = {
   e_name : string;                      (* Name of element. *)
@@ -47,6 +48,7 @@ let e name attrs children =
  *)
 let rec node_to_chan ?(indent = 0) chan = function
   | PCData str -> output_string chan (xml_quote_pcdata str)
+  | Comment str -> output_spaces chan indent; fprintf chan "<!-- %s -->" str
   | Element e -> element_to_chan ~indent chan e
 and element_to_chan ?(indent = 0) chan
     { e_name = name; e_attrs = attrs; e_children = children } =
@@ -65,6 +67,10 @@ and element_to_chan ?(indent = 0) chan
       | PCData _ as child ->
         last_child_was_element := false;
         node_to_chan ~indent:(indent+2) chan child;
+      | Comment _ as child ->
+        last_child_was_element := true;
+        output_char chan '\n';
+        node_to_chan ~indent:(indent+2) chan child;
     ) children;
     if !last_child_was_element then (
       output_char chan '\n';
@@ -93,6 +99,7 @@ let path_to_nodes doc path =
           List.filter (
             function
             | PCData _ -> false
+            | Comment _ -> false
             | Element e when e.e_name = p -> true
             | Element _ -> false
           ) nodes
@@ -101,6 +108,7 @@ let path_to_nodes doc path =
             filter_map (
               function
               | PCData _ -> None
+              | Comment _ -> None
               | Element e when e.e_name = p -> Some e.e_children
               | Element _ -> None
             ) nodes in
@@ -113,7 +121,7 @@ let filter_node_list_by_attr nodes attr =
   List.filter (
     function
     | Element { e_attrs = attrs } when List.mem attr attrs -> true
-    | Element _ | PCData _ -> false
+    | Element _ | PCData _ | Comment _ -> false
   ) nodes
 
 let find_node_by_attr nodes attr =
diff --git a/v2v/DOM.mli b/v2v/DOM.mli
index 2c97f5c..b594b49 100644
--- a/v2v/DOM.mli
+++ b/v2v/DOM.mli
@@ -20,6 +20,7 @@
 
 type node =
   | PCData of string
+  | Comment of string
   | Element of element
 and element = {
   e_name : string;                      (** Name of element. *)
diff --git a/v2v/output_RHEV.ml b/v2v/output_RHEV.ml
index 5c90d36..647574a 100644
--- a/v2v/output_RHEV.ml
+++ b/v2v/output_RHEV.ml
@@ -42,7 +42,7 @@ type export_storage_domain = {
 }
 
 let append_child child = function
-  | PCData _ -> assert false
+  | PCData _ | Comment _ -> assert false
   | Element e -> e.e_children <- e.e_children @ [child]
 
 (* We set the creation time to be the same for all dates in
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index d019b16..099e8c9 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -26,11 +26,11 @@ open Utils
 open DOM
 
 let append_child child = function
-  | PCData _ -> assert false
+  | PCData _ | Comment _  -> assert false
   | Element e -> e.e_children <- e.e_children @ [child]
 
 let append_attr attr = function
-  | PCData _ -> assert false
+  | PCData _ | Comment _ -> assert false
   | Element e -> e.e_attrs <- e.e_attrs @ [attr]
 
 let create_libvirt_xml ?pool source overlays guestcaps =

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list