title: Parse XML into data structures, with a reversible common definition?
body: <p>Might any of you know of a library that can parse XML in the following way into
  data structures?</p>
  
  <pre><code>parseXML
    [xmldef| &lt;a&gt;Int&lt;/a&gt;[&lt;b&gt;String&lt;/b&gt;] |]
    "&lt;a&gt;1&lt;/a&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;b&gt;World&lt;/b&gt;"
    == (1, ["Hello", "World"])
  </code></pre>
  
  <p>The key here is that the parser takes a definition that is descriptive enough
  to deal with missing elements, lists of elements, and turn them into native data structures.</p>
  
  <p>I find the idea of this definition very attractive, and perceive it to be
  potentially very robust. E.g. it could be reversible as well to render XML.</p>
  
  <pre><code>renderXML
    [xmldef| &lt;a&gt;Int&lt;/a&gt;[&lt;b&gt;String&lt;/b&gt;] |]
    (1, ["Hello", "World"])
    == "&lt;a&gt;1&lt;/a&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;b&gt;World&lt;/b&gt;"
  </code></pre>
  
  <p>Here is another example on how I imagine this could work:</p>
  
  <pre><code>data Coord = Coord Int Int
  instance XMLDef Coord where
    xmlDefinition = [xmldef| &lt;x&gt;Int&lt;/x&gt;&lt;y&gt;Int&lt;/y&gt; |]
  
  
  coordsDef = [xmldef| [&lt;coord&gt;Coord&lt;/coord&gt;] |] 
  
  parseXML coordsDef "" == []
  parseXML coordsDef longXML == [Coord 1 2, Coord 3 4]
  longXML = "&lt;coord&gt;&lt;x&gt;1&lt;/x&gt;&lt;y&gt;2&lt;/y&gt;&lt;/coord&gt;&lt;coord&gt;&lt;x&gt;3&lt;/x&gt;&lt;y&gt;4&lt;/y&gt;&lt;/coord&gt;"
  
  renderXML coordsDef [Coord 5 6] == "&lt;coord&gt;&lt;x&gt;5&lt;/x&gt;&lt;y&gt;6&lt;/y&gt;&lt;/coord&gt;"
  </code></pre>
  
  <p>Quite succinct and powerful notation, it seems. Does something like this
  exist for Haskell?
  Or for any other language for that matter?</p>
  
  <p>I know about <a href="https://hackage.haskell.org/package/syntax" rel="nofollow">this library (named 'syntax')</a>
  So maybe it could be used to build the above mentioned API if no other option
  exists at this point.</p>
  
  <h3>So far</h3>
  
  <p>I've used <a href="http://hackage.haskell.org/package/xml" rel="nofollow">the library named 'xml'</a>, which is fine for simple tasks,
  but it has two downsides: It doesn't support a common definition to both parse
  and render XML, and it gets quite a bit more verbose than the syntax I outline
  above in my experience.</p>
  
  <p>While looking around, I found that haxml, hxt and hexpat are also popular
  choices. However they too seem to be limited in the same way: No reversible
  definitions supported, and quite a bit more verbose than what I am looking for
  with this question.</p>