Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Everything a String? #10

Open
mcapodici opened this issue Feb 7, 2018 · 2 comments
Open

Make Everything a String? #10

mcapodici opened this issue Feb 7, 2018 · 2 comments

Comments

@mcapodici
Copy link

Would be nice to control how the values are decoded. I would like everything decoded as a string, and don't attempt to parse as Float, Bool, etc.

Maybe an option to pass in the list of decoders to decode?

@Jacob-Nielsen
Copy link

Jacob-Nielsen commented Feb 21, 2018

This could be a solution:

mystring: Value -> Result String String
mystring value =
    let
        res =  case value of
                   Xml.StrNode a -> Ok a
                   Xml.IntNode a -> Ok (toString a)
                   Xml.FloatNode a -> Ok (toString a)
                   Xml.BoolNode a -> Ok (toString a)
                   Xml.Object [] -> Ok ""
                   Xml.Object _ -> Xml.Query.string value
                   Xml.Tag _ _ _ -> Xml.Query.string value
                   Xml.DocType _ _ -> Xml.Query.string value
        replaceXmlEscapes = (String.split "&lt;") >> (String.join "<")
                            >> (String.split "&gt;") >> (String.join ">")
                            >> (String.split "&amp;") >> (String.join "&")
    in
        case res of
            Ok a -> Ok (replaceXmlEscapes a)
            _ -> res

Use in the "tag" instead of "string" when the field actually contains a number.
(tag "al-kort" mystring value)

@schoettl
Copy link

Hi, I just stumbled on this issue.

In this PR, I added encode and decode settings.

  • decode settings
    • selection of strings that are parsed as NullNode
    • selection of strings that are parsed as True/False

Passing a list of decoders would be a nice general solution.

But, to keep it simple, you could use my PR and pass:

decode
   { defaultDecodeSettings | trueValues = [], falseValues = [], nullValues = [] }
   "<your xml>"

where

defaultDecodeSettings =
    { nullValues = [ "" ], trueValues = [ "true" ], falseValues = [ "false" ] }

A setting parseNumbers : Bool could easily be added. Maybe I'll do that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants