# Using Elm for parsing deeply nested XML

**URL:** https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323
**Category:** Learn
**Created:** [March 16, 2020, 2:15am UTC](https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323 "2020-03-16T02:15:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DullBananas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dullbananas/32/3709_2.png) [@DullBananas](https://discourse.elm-lang.org/u/DullBananas)
#### Post date: [March 16, 2020, 2:15am UTC](https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323/1 "2020-03-16T02:15:53Z")

</div>

I’m creating a browser-based world edit tool for Survivalcraft, and I have to parse XML using Elm. You can see an example of the XML format [here](https://www.pythonanywhere.com/user/dullw/shares/580ee4cb70d144d5b2889da5b563cfe0/).

- The root element of the XML has 2 children: and .

- contains many elements.

- and each can contain and elements.

- has Name, Type, and Value attributes.

- has a Name attribute and contains and elements.

I defined some types that I want to use to represent the file:

```auto
type XMLItem -- Represents either a Value or Values XML tag
    = Values String (List XMLItem) -- name and list of xml items
    | ValueBool String Bool
    | ValueInt String Int
    | ValueLong String Int
    | ValueFloat String Float
    | ValueDouble String Float
    | ValuePoint3 String Int Int Int
    | ValueVector3 String Float Float Float
    | ValueQuaternion String Float Float Float Float
    | ValueString String String
    | ValueGameMode String GameMode
    | ValuePlayerClass String PlayerType

type alias ProjectFile = -- Represents the whole file
    { subsystems : List XMLItem
    , entities : List ProjectEntity
    , version : GameVersion
    , guid : String
    }

type alias ProjectEntity = -- Represents an Entity tag
    { id : Int
    , guid : String
    , name : String
    , content : List XMLItem -- The child nodes
    }

```

I want to make a function that takes the contents of the XML file as a string and returns a ProjectFile record. I tried doing it, but the implementation I came up with was not finished and it’s too complex. I deleted the code and I don’t have it anywhere anymore. What is the best way to implement a function that does this?

---

<div class="post-metadata">

### Author: ![Niklasja](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Niklasja](https://discourse.elm-lang.org/u/Niklasja)
#### Post date: [March 16, 2020, 2:44am UTC](https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323/2 "2020-03-16T02:44:59Z")

</div>

Hi,

I haven’t tried these myself, but perhaps these two packages are worth looking at;  
[https://package.elm-lang.org/packages/billstclair/elm-xml-eeue56/latest/](https://package.elm-lang.org/packages/billstclair/elm-xml-eeue56/latest/)  
[https://package.elm-lang.org/packages/ymtszw/elm-xml-decode/latest/](https://package.elm-lang.org/packages/ymtszw/elm-xml-decode/latest/)

Looks like the last one has gone for an API similar to Elm’s JSON library. Might be helpful.

Edit: I wasn’t able to view the XML example you linked to. Don’t have an account there.

---

<div class="post-metadata">

### Author: ![DullBananas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dullbananas/32/3709_2.png) [@DullBananas](https://discourse.elm-lang.org/u/DullBananas)
#### Post date: [March 16, 2020, 3:36am UTC](https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323/4 "2020-03-16T03:36:26Z")

</div>

I already tried those libraries, but I probably still need to use one of those. I just need to know exactly how I can use them for the type of XML format that I’m dealing with here. But thanks for trying to be helpful. Already having a better experience with this site than with StackOverflow.

I will try putting the XML code on some other website. I can’t put it on GitHub because my account there is flagged (probably because of a repository I created that said something like “star this repo or else you are gay”), and I don’t want to put the XML code directly in here because it’s very large.

Edit: I put the file on Google Drive: [https://drive.google.com/file/d/1LXUuqbvwnsSHEZHaKu8BtFcvwXKgY3j3/view?usp=sharing](https://drive.google.com/file/d/1LXUuqbvwnsSHEZHaKu8BtFcvwXKgY3j3/view?usp=sharing)

---

<div class="post-metadata">

### Author: ![DullBananas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dullbananas/32/3709_2.png) [@DullBananas](https://discourse.elm-lang.org/u/DullBananas)
#### Post date: [March 17, 2020, 3:43am UTC](https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323/5 "2020-03-17T03:43:25Z")

</div>

I’m figuring it out now. I started rewriting my parser several hours ago and it’s going well. I’m using function pipelines to do it. But I am having a problem with records. I will make a separate post about that. Again, thanks for helping when Stack Overflow didn’t.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [March 27, 2020, 3:43am UTC](https://discourse.elm-lang.org/t/using-elm-for-parsing-deeply-nested-xml/5323/6 "2020-03-27T03:43:29Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
