Skip to content

Instantly share code, notes, and snippets.

@nacengineer
Created October 3, 2020 22:51
Show Gist options
  • Save nacengineer/fc0b3bd60a2bfe16f8cb292e5bc3ad5a to your computer and use it in GitHub Desktop.
Save nacengineer/fc0b3bd60a2bfe16f8cb292e5bc3ad5a to your computer and use it in GitHub Desktop.
alias Person
{:ok, xml} =
["people.xml"]
|> Path.join()
|> File.read()
people = Person.map(xml)
IO.inspect(people)
defmodule Person do
import SweetXml
@schema [
person: [
~x[//people/person]l,
name: ~x[./name/text()]s,
age: ~x[./age/text()]i
]
]
def map(xml_string) do
SweetXml.xmap(xml_string, @schema)
end
end
@allenwyma
Copy link

Thank you! We have used this as a base for our next video! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment