sax_map v0.1.0 SAXMap View Source
XML to Map conversion.
SAXMap uses a SAX parser (built on top of Saxy) to transfer an XML string into a Map
containing a collection of pairs where the key is the node name and the value is its content.
Link to this section Summary
Functions
Use Saxy.parse_string/4
with a custom SAX parse handler to extract a Map
containing a collection of pairs where the key is the node name
and the value is its content.
Link to this section Functions
Link to this function
from_string(xml)
View Sourcefrom_string(xml :: String.t()) :: {:ok, map :: map()} | {:error, exception :: Saxy.ParseError.t()}
Use Saxy.parse_string/4
with a custom SAX parse handler to extract a Map
containing a collection of pairs where the key is the node name
and the value is its content.
Example
Here is an example:
iex> xml = """
...> <?xml version="1.0" encoding="UTF-8"?>
...> <thread>
...> <title>Hello</title>
...> <items>
...> <item>item1</item>
...> <item>item2</item>
...> </items>
...> </thread>
...> """
iex> SAXMap.from_string(xml)
{:ok,
%{
"thread" => %{"items" => %{"item" => ["item1", "item2"]}, "title" => "Hello"}
}}
Please notice that both XML attributes and comments are ignored.