diff options
Diffstat (limited to 'lib/xml.ml')
-rw-r--r-- | lib/xml.ml | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -31,11 +31,13 @@ let element_to_string ?(indent = 2) (el : element) = (** [element_to_string element] is a string representation of the underlying XML in [element], for debugging purposes. - Note this isn't serialization: namely, XML namespaces are ignored. *) - let rec element_to_string {local_name; attributes; children; _} = + Note this isn't serialization: namely, XML namespaces are inferred and don't exist + in the actual [element]. *) + let rec element_to_string parent {local_name; attributes; children; namespace} = let attributes = - String.concat "" - (List.map (fun (n, a) -> " " ^ n ^ "=\"" ^ a ^ "\"") attributes) + (if parent == namespace then "" else " xmlns=\"" ^ namespace ^ "\"") ^ + String.concat "" + (List.map (fun (n, a) -> " " ^ n ^ "=\"" ^ a ^ "\"") attributes) in let tab s = String.split_on_char '\n' s |> String.concat ("\n" ^ String.make indent ' ') @@ -46,9 +48,9 @@ let element_to_string ?(indent = 2) (el : element) = | _ -> ">" ^ (children |> List.map (Either.fold - ~left:element_to_string + ~left:(element_to_string namespace) ~right:(fun x -> "\n" ^ x)) |> String.concat "" |> tab) ^ "\n</" ^ local_name ^ ">" - in element_to_string el |> String.trim + in element_to_string "" el |> String.trim |