Julian
Julian

Reputation: 763

Create an xml file in Haskell without using XML library

I am a complete noob at Haskell and I am trying to do a project. I need to be able to create an xml based on the user input. For example

I ask a user if they want to enter a name, if they choose yes, then it should create this as a simple xml

<person>
     <name>Chosen name</name>
</person>

Any idea on how I can achieve this? This has to be done without using xml libraries

Thank you so much in advance for any answers

I havent really done much as I am not sure how to proceed, this is what I've done so far

main = do   
    putStrLn   "Would you like to add a person?"
    putStrLn   "1 = Yes"
    putStrLn   "2 = No"
    choice <-getLine

    --some sort of if statement here to decide what to do next

I have also tried to append file this way

createName = appendFile "addPerson.xml" openName
openName = "<name>"

but I need this to be called once they user enters their name

Upvotes: 0

Views: 174

Answers (1)

Gabriella Gonzalez
Gabriella Gonzalez

Reputation: 35099

I'll give you a little bit of a hint:

main = do   
    putStrLn "Would you like to add a person?"
    putStrLn "1 = Yes"
    putStrLn "2 = No"
    choice <- readLn
    case choice of
        1 -> do
            ... -- Add a person
        2 -> do
            ... -- Do not add a person
        _ -> do
            ... -- The user entered an invalid input

I recommend that you read Learn you a Haskell for Great Good so that you can learn basic Haskell syntax and idioms.

Upvotes: 4

Related Questions