Saxy v1.2.0 Saxy.SimpleForm View Source
Provides functions to parse a XML document to simple-form data structure.
Data structure
Simple form is a basic representation of the parsed XML document. It contains a root element, and all elements are in the following format:
element = {tag_name, attributes, content}
content = (element | binary)*
See “Types” section for more information.
Link to this section Summary
Functions
Parse given string into simple form
Link to this section Types
Link to this section Functions
Link to this function
parse_string(data, options \\ [])
View Source
parse_string(data :: binary(), options :: Keyword.t()) :: {:ok, t()} | {:error, exception :: Saxy.ParseError.t()}
Parse given string into simple form.
Options
:expand_entity
- specifies how external entity references should be handled. Three supported strategies respectively are::keep
- keep the original binary, for exampleOrange ®
will be expanded to"Orange ®"
, this is the default strategy.:skip
- skip the original binary, for exampleOrange ®
will be expanded to"Orange "
.{mod, fun, args}
- take the applied result of the specified MFA.
Examples
Given this XML document.
iex> xml = """
...> <?xml version="1.0" encoding="utf-8" ?>
...> <menu>
...> <movie url="https://www.imdb.com/title/tt0120338/" id="tt0120338">
...> <name>Titanic</name>
...> <characters>Jack & Rose</characters>
...> </movie>
...> <movie url="https://www.imdb.com/title/tt0109830/" id="tt0109830">
...> <name>Forest Gump</name>
...> <characters>Forest & Jenny</characters>
...> </movie>
...> </menu>
...> """
iex> Saxy.SimpleForm.parse_string(xml)
{:ok,
{"menu", [],
[
"\n ",
{
"movie",
[
{"url", "https://www.imdb.com/title/tt0120338/"},
{"id", "tt0120338"}
],
[
"\n ",
{"name", [], ["Titanic"]},
"\n ",
{"characters", [], ["Jack & Rose"]},
"\n "]
},
"\n ",
{
"movie",
[
{"url", "https://www.imdb.com/title/tt0109830/"},
{"id", "tt0109830"}
],
[
"\n ",
{"name", [], ["Forest Gump"]},
"\n ",
{"characters", [], ["Forest & Jenny"]},
"\n "
]
},
"\n"
]}}