willemdj / erlsom

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

xsi:nil="true" & integer #21

Closed lego12239 closed 10 years ago

lego12239 commented 10 years ago

Hello.

When i get a response from a soap server with empty elements (which marked by xsi:nil="true" attribute and nillable="true" attribute in a schema), erlsom crashes with the next error:

{error,{decoding,[{exception,{error,"Wrong Type: /integer"}},
                  {stack,[{'#PCDATA',integer,[]},
                          'p:ItemsAvailResult','p:ArrayOfItemsAvailResult',
                          'p:getItemsAvailResponse','soap:Body','soap:Envelope']},
                  {received,{endElement,[],"AvailableClient_RG",[]}}]}}

If i change an element type from int to string in the wsdl schema, everything works fine.

willemdj commented 10 years ago

Hi,

I ran a simple test, but that seemed to work without problems. Can you send me an example XSD and XML?

Regards, Willem

lego12239 commented 10 years ago

XSD:

<xsd:complexType name="ItemsAvailResult">
  <xsd:all>
    <xsd:element name="No" type="xsd:string" nillable="true"/>
    <xsd:element name="PriceClient" type="xsd:float" nillable="true"/>
    <xsd:element name="PriceClient_RG" type="xsd:float" nillable="true"/>
    <xsd:element name="PriceClient_MSK" type="xsd:float" nillable="true"/>
    <xsd:element name="AvailableClient" type="xsd:float" nillable="true"/>
    <xsd:element name="AvailableClient_RG" type="xsd:int" nillable="true"/>
    <xsd:element name="AvailableClient_MSK" type="xsd:int" nillable="true"/>
    <xsd:element name="AvailableExpected" type="xsd:int" nillable="true"/>
    <xsd:element name="AvailableExpectedNext" type="xsd:int" nillable="true"/>
    <xsd:element name="DateExpectedNext" type="xsd:string" nillable="true"/>
  </xsd:all>
</xsd:complexType>
<xsd:complexType name="ArrayOfItemsAvailResult">
  <xsd:sequence>
    <xsd:element name="item" type="tns:ItemsAvailResult" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="getItemsAvailResponse">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="getItemsAvailResult" type="tns:ArrayOfItemsAvailResult"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http:/\
/www.w3.org/2001/XMLSchema-instance" xmlns:ns1="https://api.merlion.com/dl/mlservice2">
  <SOAP-ENV:Body>
    <ns1:getItemsAvailResponse>
      <getItemsAvailResult>
        <item>
          <No xsi:nil="true"/>
          <PriceClient xsi:nil="true"/>
          <PriceClient_RG xsi:nil="true"/>
          <PriceClient_MSK xsi:nil="true"/>
          <AvailableClient xsi:nil="true"/>
          <AvailableClient_RG xsi:nil="true"/>
          <AvailableClient_MSK xsi:nil="true"/>
          <AvailableExpected xsi:nil="true"/>
          <AvailableExpectedNext xsi:nil="true"/>
          <DateExpectedNext xsi:nil="true"/>
        </item>
      </getItemsAvailResult>
    </ns1:getItemsAvailResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
willemdj commented 10 years ago

I see... It is because of the combination with "xsd:all", I guess. I'll see what I can do about it.

lego12239 commented 10 years ago

Thank you!

willemdj commented 10 years ago

Fixed. Note that this fix also has impact on xsi:nil values for elements within xsd:all types that are not integers: they will now contain 'nil'.