{"id":22093211,"url":"https://github.com/iadvize/xyleme","last_synced_at":"2025-07-07T16:35:37.266Z","repository":{"id":42191495,"uuid":"478442983","full_name":"iadvize/xyleme","owner":"iadvize","description":"A quick way to parse XML structures","archived":false,"fork":false,"pushed_at":"2023-04-07T21:01:30.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-29T07:14:47.320Z","etag":null,"topics":["cats","parser","scala","xml"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/iadvize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-06T07:05:52.000Z","updated_at":"2022-04-08T15:25:32.000Z","dependencies_parsed_at":"2024-12-01T03:13:23.064Z","dependency_job_id":"b7d7f37f-a17a-48a7-9a8a-e55dbae2977a","html_url":"https://github.com/iadvize/xyleme","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/iadvize%2Fxyleme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fxyleme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fxyleme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fxyleme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iadvize","download_url":"https://codeload.github.com/iadvize/xyleme/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245188891,"owners_count":20574865,"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":["cats","parser","scala","xml"],"created_at":"2024-12-01T03:13:17.190Z","updated_at":"2025-03-24T00:27:03.077Z","avatar_url":"https://github.com/iadvize.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Xyleme\n_A quick way to parse XML structures_\n\n[![codecov](https://codecov.io/gh/iadvize/xyleme/branch/main/graph/badge.svg?token=K6BM30SJX7)](https://codecov.io/gh/iadvize/xyleme)\n\n\n## Motivation\n\nXyleme comes from the frustration of having to quickly parse XML elements. \nIn my experience, two well-known libraries enable to parse XML in Scala : \n- native [scala-xml](https://github.com/scala/scala-xml) enables fast formatting, but is tedious while parsing \n- [scalaxb](https://github.com/eed3si9n/scalaxb) is safer, but needs XSD to be defined and sometimes is not ideal (complex structure, duplicate names)\n\nThe idea of Xyleme is to use [circe](https://github.com/circe/circe) as inspiration to enable safer and easier parsing of xml elements.\n\n## Getting started\n\nFirst, add Xyleme dependency to your module definition in `build.sbt`\n```sbt\nlibraryDependencies += \"com.iadvize\" %% \"xyleme\" % \"\u003cversion\u003e\"\n```\n\nIt brings to transitive dependencies : [cats-core](https://github.com/typelevel/cats) and [scala-xml](https://github.com/scala/scala-xml)\n\nThen, use `ElemDecoder` and `ElemCursor` to parse your nodes \n\n```scala\nimport com.iadvize.xyleme._\nimport scala.util.Try\nimport cats.syntax.apply._\n\ncase class Price(value: Long)\ncase class Album(name: String, artist: String, price: Price)\n\nimplicit val priceDecoder: TextDecoder[Price] = TextDecoder.fromOption(\"Price\") { str =\u003e\n  Try((BigDecimal(str) * 100).toLongExact).toOption.map(Price)\n}\n\nimplicit val decoder: ElemDecoder[Album] = ElemDecoder.instance { elem =\u003e\n  (\n    elem.downElem(\"name\").text.as[String],\n    elem.downElem(\"artist\").text.as[String],\n    elem.attribute(\"price\").as[Price]\n    ).mapN(Album)\n}\n\nval xml = \u003calbums\u003e\n  \u003calbum price=\"15.00\"\u003e\n    \u003cname\u003eOne Size Fits All\u003c/name\u003e\n    \u003cartist\u003eFrank Zappa\u003c/artist\u003e\n  \u003c/album\u003e\n  \u003calbum price=\"13.00\"\u003e\n    \u003cname\u003eMaggot Brain\u003c/name\u003e\n    \u003cartist\u003eFunkadelic\u003c/artist\u003e\n  \u003c/album\u003e\n\u003c/albums\u003e\n\nval albums = ElemCursor.from(xml).downElem(\"album\").as[List[Album]]\n\nprintln(albums)\n// Valid(List(\n//    Album(One Size Fits All,Frank Zappa,Price(1500)), \n//    Album(Maggot Brain,Funkadelic,Price(1300))\n// ))\n```\n\nXyleme is able to detect formatting errors. These are accumulated thanks to the [ValidatedNec](https://typelevel.org/cats/datatypes/validated.html) datatype\n\n```scala\nval wrongXml = \u003calbums\u003e\n  \u003calbum price=\"not-a-price\"\u003e\n    \u003cname\u003eOne Size Fits All\u003c/name\u003e\n    \u003cartist\u003eFrank Zappa\u003c/artist\u003e\n  \u003c/album\u003e\n  \u003calbum price=\"13.00\"\u003e\n    \u003cname\u003eMaggot Brain\u003c/name\u003e\n  \u003c/album\u003e\n\u003c/albums\u003e\n\nval wrongAlbums = ElemCursor.from(wrongXml).downElem(\"album\").as[List[Album]]\n\nprintln(wrongAlbums)\n// Invalid(Chain(\n//    Failed to parse field into Price, path: /albums/album/@price, text: not-a-price, \n//    Failed to find field at given path: /albums/album[2]/artist/text()\n// ))\n```\n\n## Contribute\n\nXyleme is currently in development : \n- its API is not stable and could change\n- it certainly has a lot of edge cases\n- its current implementation is not optimized (multiple traversals of DOM)\n\nFeel free to contribute :). I already think of several improvements: \n- a stax cursor implementation, quite complex, but I think it could be possible\n- add property based tests to improve coverage of edge cases\n\nContribution guidelines are described in [CONTRIBUTING.md](CONTRIBUTING.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiadvize%2Fxyleme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiadvize%2Fxyleme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiadvize%2Fxyleme/lists"}