When using an xsd:attributeGroup inside a xml element, the order of the attributes of the group in a generated .hrl file does not match the order of the attributes when using erlsom:scan/2 or erlsom:write/2.
XSD Example test.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="attrinfo">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attributeGroup ref="_DefaultAttributes"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:attributeGroup name="_DefaultAttributes">
<xsd:attribute name="a" type="xsd:string"/>
<xsd:attribute name="b" type="xsd:string"/>
<xsd:attribute name="c" type="xsd:string"/>
</xsd:attributeGroup>
</xsd:schema>
XML Example test.xml:
<?xml version='1.0' encoding='UTF-8'?>
<attrinfo a ='a' c='c' Z="Z" b='b' x0="0"/>
Create test.hrl:
erl -eval 'erlsom:write_xsd_hrl_file("test.xsd","test.hrl")' -s erlang halt
Erlang code Example test.erl:
-module(test).
-export([bug/0]).
-include("test.hrl").
bug() ->
{ok, Model} = erlsom:compile_xsd_file("test.xsd"),
{ok, Xml} = file:read_file("test.xml"),
{ok, Result, _R} = erlsom:scan(Xml, Model),
io:format("a=~p b=~p c=~p~n", [Result#attrinfo.a, Result#attrinfo.b, Result#attrinfo.c]).
Result:
a="c" b="b" c="a"
The attached patch fixes this problem.
patches xsd:attributeGroup handling
I fixed this (finally...). The fix is in the github repository, together with some other improvements - http://github.com/willemdj/erlsom.