xmerl "simple" format is similar to yours: (pay attention to the third value, the list of child elements)
Data = {myNode,[{foo,"Foo"},{bar,"Bar"}], []}.
This can be "exported" to XML for use as a string:
> lists:flatten(xmerl:export_simple([Data], xmerl_xml)). "<?xml version=\"1.0\"?><myNode foo=\"Foo\" bar=\"Bar\"/>"
Or is written to the file:
> file:write_file("/tmp/foo.xml", xmerl:export_simple([Data2], xmerl_xml)). ok
Note that export_simple accepts a list of elements, not a single root element. Also, depending on what you do with the result, alignment may not be necessary.
legoscia
source share