sweet_xml
sweet_xml copied to clipboard
Add cast modifier for boolean values
Hi there! Thank you for making sweet_xml
, it works amazingly well. 😀
While parsing an XML with some boolean values, I realised that boolean values are actually standardised in the XML Schema specification, with values true
and false
(and non-canonically 0
and 1
).
I think having a b
modifier for the ~x
sigil would be a nice addition! I have included a test case for casting with b
, and checking for the sigil with b
, bl
, and lb
Please let me know what you think, and if I need to make any additional changes!
Thanks again! 👋
Hi,
This would be a very helpful feature to have. Any reason this wasn't merged?
@awetzel any update on this?
@lucidstack If you can rebase and fix the conflicts, I can handle the merge.
Hey there, I need this feature for a project I'm trying to use sweet_xml for. Can we get the conflicts fixed and get this merged?
BTW you can do this using transform_by/2
~x"./first/text()" |> transform_to_boolean()
defp transform_to_boolean(arg) do
transform_by(arg, fn
'false' -> false
'true' -> true
"" -> nil
end)
end