diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-24 13:39:22 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-24 13:39:22 +0200 |
commit | c6691a4d2811d542bc90a212a2a9a8bb345d7d02 (patch) | |
tree | f3ebc2fd61f2b27fd3005a845dd554e14dc3ddab | |
parent | 74d3d2fe21dcb7e988c9c0db531ecad6f4fd31fb (diff) |
feat(xml): add xmlns to debugging
-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 |