# PostgreSQL XML data and Elixir / Ecto?

**URL:** <https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317>\
**Category:** Questions\
**Tags:** ecto, xml\
**Created:** [June 16, 2025, 10:31pm UTC](https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317 "2025-06-16T22:31:16Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![christhekeele](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/christhekeele/32/1039_2.png) [@christhekeele](https://forum.elixirforum.com/u/christhekeele)\
**Post date:** [June 17, 2025, 6:42pm UTC](https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317/5 "2025-06-17T18:42:33Z")

</div>

> [@silverdr](#):
>
> Although even on parsers/builders (especially the latter) choice seems to be limited.

I’m don’t know how expansive the choice needs to be, really—parsing and building are pretty straightforward until you need SAX, and even then you just use a SAX parser if you’re memory constrained. I’ve built a few XML-handling things in Elixir just fine with [`sweet_xml`](https://hex.pm/packages/sweet_xml) and [`xml_builder`](https://hex.pm/packages/xml_builder). Usually end up with something like this as my main entrypoint, with application-specific helpers for common workflows, and submodules for specific domains (ex `XML.SOAP`).

> **XML module**
>
> ```elixir
> defmodule XML do
> defmacro __using__ (_options \\ []) do
> quote do
> import XML, only: [sigil_x: 1, sigil_x: 2]
> end
> end
> 
> @type document() :: SweetXml.doc()
> @type element() :: SweetXml.xmlElement()
> 
> ####
> # XML builder functions
> ##
> 
> defdelegate document(elements), to: XmlBuilder
> defdelegate document(name, attrs_or_content), to: XmlBuilder
> defdelegate document(name, attrs, content), to: XmlBuilder
> 
> defdelegate element(name), to: XmlBuilder
> defdelegate element(name, attrs), to: XmlBuilder
> defdelegate element(name, attrs, content), to: XmlBuilder
> 
> ####
> # XML parser functions
> ##
> defdelegate generate(any, options \\ []), to: XmlBuilder
> defdelegate parse(document, options \\ []), to: SweetXml
> defdelegate sigil_x(path, modifiers \\ []), to: SweetXml
> defdelegate xpath(parent, spec, subspec \\ []), to: SweetXml
> end
> 
> ```

> [@silverdr](#):
>
> I guess the option is to somehow treat the column as text and then do some string parsing, etc.

That really depends on what you’re doing with the XML. If you’re looking for feedback, share some details about the problem you’re trying to solve with us!

---

_[View the full topic](https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317)._
