willemdj / erlsom

XML parser for Erlang
GNU Lesser General Public License v3.0
266 stars 103 forks source link

Exception error: no match of right hand side value #49

Closed Karberlane closed 8 years ago

Karberlane commented 8 years ago

Hi, I have the following error:

** exception error: no match of right hand side value 
                    {error,
                     {'EXIT',
                      {error,
                       [{exception,
                         {{badmatch,[]},
                          [{erlsom_parse,insertValue,2,
                            [{file,"src/erlsom_parse.erl"},{line,1171}]},
                           {erlsom_parse,stateMachine,2,
                            [{file,"src/erlsom_parse.erl"},{line,717}]},
                           {erlsom_parse,xml2StructCallback,2,
                            [{file,"src/erlsom_parse.erl"},{line,305}]},
                           {erlsom_sax_utf8,wrapCallback,2,
                            [{file,"src/erlsom_sax_utf8.erl"},{line,1408}]},
                           {erlsom_sax_utf8,parseContentLT,2,
                            [{file,"src/erlsom_sax_utf8.erl"},{line,907}]},
                           {erlsom_sax_utf8,parse,2,
                            [{file,"src/erlsom_sax_utf8.erl"},{line,196}]},
                           {erlsom,scan2,3,
                            [{file,"src/erlsom.erl"},{line,212}]},
                           {erlsom,scan_file,3,
                            [{file,"src/erlsom.erl"},{line,228}]}]}},
                        {stack,
                         [{'#text',char,"playannouncement"},
                          paramType,mscivrType]},
                        {received,{endElement,[],"param",[]}}]}}}

When I try open the following xml file:

<?xml version="1.0" encoding="UTF-8"?>
<mscivr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="msc-ivr.xsd">
    <param name="mode">playannouncement</param>
</mscivr>

with xsd schema:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:complexType name="mscivrType">
        <xsd:sequence>
                <xsd:element name="param" type="paramType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="mscivr" type="mscivrType"/>

    <xsd:complexType name="paramType" mixed="true">
        <xsd:attribute name="name" type="xsd:string" use="required"/>
    </xsd:complexType>
</xsd:schema>

If you replace the scheme on

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:complexType name="mscivrType">
        <xsd:sequence>
                <xsd:element name="param" type="paramType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="mscivr" type="mscivrType"/>

    <xsd:complexType name="paramType">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string"/>
        </xsd:simpleContent>
        <xsd:attribute name="name" type="xsd:string" use="required"/>
    </xsd:complexType>
</xsd:schema>

we get the following result

{mscivrType,[{{"schemaLocation","http://www.w3.org/2001/XMLSchema-instance"},
                "msc-ivr.xsd"}],
              {paramType,[],"mode","playannouncement"}}

That result I expected in the first case. I think that the problem in parsing mixed type. I would like to hear your comments on that. Thanks.

willemdj commented 8 years ago

Solved the issue. Note that the result will in fact look like this:

{mscivrType,[{{"schemaLocation","http://www.w3.org/2001/XMLSchema-instance"},"msc-ivr.xsd"}],
                     {paramType,[],"mode",["playannouncement"]}}