# Static XML to Elixir "term"

**URL:** <https://forum.elixirforum.com/t/static-xml-to-elixir-term/46482>\
**Category:** Questions\
**Tags:** xml\
**Created:** [March 9, 2022, 6:30pm UTC](https://forum.elixirforum.com/t/static-xml-to-elixir-term/46482 "2022-03-09T18:30:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [March 9, 2022, 9:30pm UTC](https://forum.elixirforum.com/t/static-xml-to-elixir-term/46482/4 "2022-03-09T21:30:30Z")

</div>

The `@external_resource` module attribute is a good place to start:

> **[Module — Elixir v1.20.2](https://elixir.hexdocs.pm/Module.html)**

You could point that at your XML file, then parse it into a module attribute:

```elixir
defmodule BagOfXml do
  @external_resource "path/to/some.xml"

  @parsed_data SomeOtherModule.parse("path/to/some.xml")

  def lookup_thing(id) do
    # use @parsed_data and id to do stuff
  end
end

```

This will call `SomeOtherModule.parse` at _compile-time_ (it cannot be a function in the same file) and store the resulting data in the compiled BEAM file.

`@external_resource` will ensure that if the XML file changes the module will be recompiled.

---

_[View the full topic](https://forum.elixirforum.com/t/static-xml-to-elixir-term/46482)._
