在不使用XML库的情况下在Haskell中创建一个xml文件 [英] Create an xml file in Haskell without using XML library
问题描述
我需要能够根据用户输入创建一个xml。
例如
我询问用户是否要输入名称,如果他们选择yes,那么它应该创建一个简单的xml
< person>
<名称>选择的名称< /名称>
< / person>
关于如何实现这一点的任何想法?必须在不使用xml库的情况下完成
非常感谢您提供任何答案
我没有做太多的事情,因为我不知道如何继续,这是我迄今为止所做的工作。
main = do
putStrLn你想添加一个人吗?
putStrLn1 =是
putStrLn2 =否
choice< -getLine
- 某些if语句可以决定做什么下一个
我也试着用这种方式追加文件
createName = appendFileaddPerson.xmlopenName
openName =< name>
但我需要在用户输入名称时调用它
我会给你一些提示:
main = do
putStrLn你想添加一个人吗?
putStrLn1 =是
putStrLn2 =否
choice< - readLn
的案例选择1 - >做
... - 添加一个人
2 - >做
... - 不要添加一个人
_ - >做
... - 用户输入了无效输入
我建议您阅读向您学习Haskell for Great Good ,以便学习基本的Haskell语法和习惯用法。
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
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.
这篇关于在不使用XML库的情况下在Haskell中创建一个xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!