Created
October 3, 2020 22:51
-
-
Save nacengineer/fc0b3bd60a2bfe16f8cb292e5bc3ad5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias Person | |
{:ok, xml} = | |
["people.xml"] | |
|> Path.join() | |
|> File.read() | |
people = Person.map(xml) | |
IO.inspect(people) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! We have used this as a base for our next video! 👍