{"id":18250449,"url":"https://github.com/jhedev/xml-conduit-generics","last_synced_at":"2025-04-08T20:27:55.480Z","repository":{"id":13314491,"uuid":"16001048","full_name":"jhedev/xml-conduit-generics","owner":"jhedev","description":"Library to create xml representation of data type based on xml-conduit and GHC Generics","archived":false,"fork":false,"pushed_at":"2014-01-17T14:21:44.000Z","size":140,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T16:01:59.085Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jhedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-17T13:59:47.000Z","updated_at":"2014-05-30T05:56:33.000Z","dependencies_parsed_at":"2022-08-29T11:32:05.267Z","dependency_job_id":null,"html_url":"https://github.com/jhedev/xml-conduit-generics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhedev%2Fxml-conduit-generics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhedev%2Fxml-conduit-generics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhedev%2Fxml-conduit-generics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhedev%2Fxml-conduit-generics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhedev","download_url":"https://codeload.github.com/jhedev/xml-conduit-generics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247921562,"owners_count":21018620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T09:44:43.250Z","updated_at":"2025-04-08T20:27:55.436Z","avatar_url":"https://github.com/jhedev.png","language":"Haskell","readme":"xml-conduit-generics\n====================\n\nSmall library based on xml-conduit to create xml representations for \nyour own data types. It's just thrown together and still missing a few\ndefault instances. \n\n#Example:\nIf we have a datatype like the following\n\n```\ndata User = User { \n                   firstName :: String,\n                   lastName :: String,\n                   age :: Int,\n                   hobbies :: [String]\n                  }\n                  deriving (Show, Generic)\n```\nWith ```deriving Generic``` we let GHC derive the generic representations.\nIf we add\n\n```\ninstance ToXml User\n```\nthe compiler will create this instance for us. So let's create two users and\nwrite the xml to a file\n\n```\nmain :: IO()\nmain = do\n        writeFile def { rsPretty = True } \"users.xml\" $ Document (Prologue [] Nothing []) root []\n            where\n                john = User \"John\" \"Doe\" 44 [\"jokes\", \"laughing\"]\n                jane = User \"Jane\" \"Doe\" 38 []\n                users = (toXml) john ++ (toXml jane)\n                root = Element \"users\" empty users\n```\nThis will create a users.xml file with the following content:\n\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cusers\u003e\n    \u003cuser\u003e\n        \u003cfirstname\u003e\n            John\n        \u003c/firstname\u003e\n        \u003clastname\u003e\n            Doe\n        \u003c/lastname\u003e\n        \u003cage\u003e\n            44\n        \u003c/age\u003e\n        \u003chobbies\u003e\n            jokeslaughing\n        \u003c/hobbies\u003e\n    \u003c/user\u003e\n    \u003cuser\u003e\n        \u003cfirstname\u003e\n            Jane\n        \u003c/firstname\u003e\n        \u003clastname\u003e\n            Doe\n        \u003c/lastname\u003e\n        \u003cage\u003e\n            38\n        \u003c/age\u003e\n        \u003chobbies/\u003e\n    \u003c/user\u003e\n\u003c/users\u003e\n```\nYou see there is a problem with the content of the hobbies tags. This is because the representation of \na list is just the concatenation of the representation of the elements and a string is represented by its \nvalue. So this will just concat all strings in the list. To avoid this behaviour we create a simple\nwrapper for our hobbies:\n\n```\ndata Hobby = Hobby String deriving (Show, Generic)\n\ninstance ToXml Hobby\n```\nAnd change the user data type as follows:\n\n```\ndata User = User { \n                   firstName :: String,\n                   lastName :: String,\n                   age :: Int,\n                   hobbies :: [Hobby]\n                  }\n                  deriving (Show, Generic)\n```\n\nAfter updating john and jane to:\n\n```\n                john = User \"John\" \"Doe\" 44 [Hobby \"jokes\", Hobby \"laughing\"]\n                jane = User \"Jane\" \"Doe\" 38 []\n```\n\nNow our xml file will look like this:\n\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cusers\u003e\n    \u003cuser\u003e\n        \u003cfirstname\u003e\n            John\n        \u003c/firstname\u003e\n        \u003clastname\u003e\n            Doe\n        \u003c/lastname\u003e\n        \u003cage\u003e\n            44\n        \u003c/age\u003e\n        \u003chobbies\u003e\n            \u003chobby\u003e\n                jokes\n            \u003c/hobby\u003e\n            \u003chobby\u003e\n                laughing\n            \u003c/hobby\u003e\n        \u003c/hobbies\u003e\n    \u003c/user\u003e\n    \u003cuser\u003e\n        \u003cfirstname\u003e\n            Jane\n        \u003c/firstname\u003e\n        \u003clastname\u003e\n            Doe\n        \u003c/lastname\u003e\n        \u003cage\u003e\n            38\n        \u003c/age\u003e\n        \u003chobbies/\u003e\n    \u003c/user\u003e\n\u003c/users\u003e\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhedev%2Fxml-conduit-generics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhedev%2Fxml-conduit-generics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhedev%2Fxml-conduit-generics/lists"}