Coder Social home page Coder Social logo

elm-xml's Introduction

elm-xml Build Status

xml parser for elm

First 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.

import Xml exposing (Value)
import Xml.Encode exposing (null)
import Xml.Decode exposing (decode)
import Xml.Query exposing (tags)

decodedXml : Value
decodedXml = 
	"""
<person>
	<name>noah</name>
	<age max="100">50</age>
</person>
<person>
	<name>josh</name>
	<age max="100">57</age>
</person>
	"""
		|> decode
		|> Result.toMaybe
		|> Maybe.withDefault null


type 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

elm-xml's People

Contributors

eeue56 avatar kitofr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.