Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eeue56/elm-xml
xml parser for elm
https://github.com/eeue56/elm-xml
elm elm-xml xml-parser
Last synced: about 1 month ago
JSON representation
xml parser for elm
- Host: GitHub
- URL: https://github.com/eeue56/elm-xml
- Owner: eeue56
- License: bsd-3-clause
- Created: 2017-01-21T19:11:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-10T21:13:15.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T20:01:39.198Z (7 months ago)
- Topics: elm, elm-xml, xml-parser
- Language: Elm
- Size: 77.1 KB
- Stars: 12
- Watchers: 3
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-xml [![Build Status](https://travis-ci.org/eeue56/elm-xml.svg?branch=master)](https://travis-ci.org/eeue56/elm-xml)
xml parser for elmFirst bring XML into Elm as a `Value`. Once imported as a Value, you can then either query the values with `Xml.Query`.
Or you can turn it back to a string using `Xml.Encode.encode`. Or pull it apart using `Xml.Encode.Value`.
In order to turn an `Xml.Value` into a record, you probably want `Xml.Query`, paired with `Result.map`.
```elm
import Xml exposing (Value)
import Xml.Encode exposing (null)
import Xml.Decode exposing (decode)
import Xml.Query exposing (tags)decodedXml : Value
decodedXml =
"""noah
50josh
57"""
|> decode
|> Result.toMaybe
|> Maybe.withDefault nulltype alias Person =
{ name: String
, age: Int
}person : Value -> Result String Person
person value =
Result.map2
(\name age ->
{ name = name
, age = age
}
)
(tag "name" string value)
(tag "age" int value)people : List Person
people =
tags "person" decodedXml
|> collect person```