willemdj / erlsom

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

error: 1 - Unexpected event, expected end-tag #45

Open lego12239 opened 9 years ago

lego12239 commented 9 years ago

Hi.

Got the next error:

{error,{decoding,[{exception,{error,{"1 - Unexpected event, expected end-tag"}}},
                  {stack,['soap:detail','soap:Fault','soap:Body',
                          'soap:Envelope']},
                  {received,{characters,"Invalid login/pass"}}]}}

while processing the next soap xml response:

<?xml version="1.0" encoding="UTF-8"?>
  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="urn://pmtv.digisoft.com/systemstatus/schema/v0.1" xmlns:ns3="urn://pmtv.digisoft.com/providerstatus/schema/v0.1" xmlns:ns5="http://schemas.microsoft.com/Message" xmlns:ns4="urn://pmtv.digisoft.com/uploadUsageRecords/wsdl/v0.1" xmlns:ns7="ws.kitd.vx2.ws.EntityNotification/EntityNotificationServiceSoap" xmlns:ns6="ws.kitd.vx2.ws.EntityNotification" xmlns:ns8="ws.kitd.vx2.ws.EntityNotification/EntityNotificationServiceSoap12" xmlns:ns11="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns12="http://schemas.datacontract.org/2004/07/GMCS.PMT.IntegrationInternal" xmlns:ns15="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns16="http://schemas.datacontract.org/2004/07/GMCS.PMT.IntegrationInternal" xmlns:ns9="http://GMCS/PMT/Integration" xmlns:lbapi="urn:api3">
    <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
        <faultcode>SOAP-ENV:Server</faultcode>
        <faultstring>error_request</faultstring>
        <detail>Invalid login/pass</detail>
      </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>

If i add the next line:

error_logger:info_msg("~p~n~p~n", [Event, ElementRecord]),

near 444 line of erlsom_parse.erl (before a throw call), i get the next output:

{characters,"Invalid login/pass"}
{'soap:detail',[],undefined}

How can i eliminate this error?

Thanks.

willemdj commented 9 years ago

Hello Oleg,

The reason for the error is that erlsom expects one or more elements as children of the tag, and not a text value.

The soap schema says:

xs:sequence /xs:sequence /xs:complexType So a valid error could look like this: SOAP-ENV:Header/SOAP-ENV:Body SOAP-ENV:FaultSOAP-ENV:Client Message does not have necessary info http://gizmos.com/order Quantity element does not have a value/PO:order Incomplete address: no zip code/PO:confirmation /SOAP-ENV:Fault /SOAP-ENV:Body/SOAP-ENV:Envelope Regards, Willem On Fri, Aug 21, 2015 at 5:05 PM, Oleg notifications@github.com wrote: > Hi. > > Got the next error: > > {error,{decoding,[{exception,{error,{"1 - Unexpected event, expected end-tag"}}}, > {stack,['soap:detail','soap:Fault','soap:Body', > 'soap:Envelope']}, > {received,{characters,"Invalid login/pass"}}]}} > > while processing the next soap xml response: > > > > SOAP-ENV:Body > SOAP-ENV:Fault > SOAP-ENV:Server > error_request > Invalid login/pass > /SOAP-ENV:Fault > /SOAP-ENV:Body > /SOAP-ENV:Envelope > > If i add the next line: > > error_logger:info_msg("~p~n~p~n", [Event, ElementRecord]), > > near 444 line of erlsom_parse.erl (before a throw call), i get the next > output: > > {characters,"Invalid login/pass"} > {'soap:detail',[],undefined} > > How can i eliminate this error? > > Thanks. > > — > Reply to this email directly or view it on GitHub > https://github.com/willemdj/erlsom/issues/45.
lego12239 commented 9 years ago

Thanks for the reply.

This is bad news, because i can't change a server side code. How can i say erlsom to accept the existent wrong format of detail element?

willemdj commented 9 years ago

You can change the schema, so that is an element of type string. (If you also get "correct" faults it becomes a bit more complicated.)

On Fri, Aug 21, 2015 at 8:16 PM, Oleg notifications@github.com wrote:

Thanks for the reply.

This is bad news, because i can't change a server side code. How can i say erlsom to accept the existent wrong format of detail element?

— Reply to this email directly or view it on GitHub https://github.com/willemdj/erlsom/issues/45#issuecomment-133519665.

lego12239 commented 9 years ago

If i'll replace here:

  <xs:element name="Fault" type="tns:Fault" />
  <xs:complexType name="Fault" final="extension" >
    <xs:annotation>
          <xs:documentation>
            Fault reporting structure
          </xs:documentation>
        </xs:annotation>
    <xs:sequence>
      <xs:element name="faultcode" type="xs:QName" />
      <xs:element name="faultstring" type="xs:string" />
      <xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
      <xs:element name="detail" type="tns:detail" minOccurs="0" />      
    </xs:sequence>
  </xs:complexType>

the line:

<xs:element name="detail" type="tns:detail" minOccurs="0" />

with:

<xs:any minOccurs="0"/>

Will erlsom parse both correct and incorrect result?

willemdj commented 9 years ago

That sounds like a good idea, give it a try.

On Sat, Aug 22, 2015 at 9:31 AM, Oleg notifications@github.com wrote:

If i'll replace here:

xs:annotation xs:documentation Fault reporting structure /xs:documentation /xs:annotation xs:sequence /xs:sequence /xs:complexType the line: with: Will erlsom parse both correct and incorrect result? — Reply to this email directly or view it on GitHub https://github.com/willemdj/erlsom/issues/45#issuecomment-133648602.
lego12239 commented 9 years ago

The results of my experiment:

with:

<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />

i get:

    {'soap:Fault',[],
                  {qname,"http://schemas.xmlsoap.org/soap/envelope/","Server",
                         "SOAP-ENV","soap"},
                  "error_request",undefined,undefined}}

with:

<xs:element name="detail" type="xs:string" minOccurs="0"/>

i get:

    {'soap:Fault',[],
                  {qname,"http://schemas.xmlsoap.org/soap/envelope/","Server",
                         "SOAP-ENV","soap"},
                  "error_request",undefined,"Invalid login/pass"}}

So, it seems i can't use any element in place of detail element or i do something wrong.

willemdj commented 9 years ago

You are right: if you just need to be able to parse the answer without getting an error, using "any" works, but if you need the information in the

element it doesn't. (It would be nice to make a change in erlsom so that "any" elements are included in the result in some generic form, that should not be so hard.) What you might also try is to make the element of type "mixed" (mixed="true"). Good luck, Willem On Sun, Aug 23, 2015 at 2:30 PM, Oleg notifications@github.com wrote: > The results of my experiment: > > with: > > > > i get: > > ``` > {'soap:Fault',[], > {qname,"http://schemas.xmlsoap.org/soap/envelope/","Server", > "SOAP-ENV","soap"}, > "error_request",undefined,undefined}} > ``` > > with: > > > > i get: > > ``` > {'soap:Fault',[], > {qname,"http://schemas.xmlsoap.org/soap/envelope/","Server", > "SOAP-ENV","soap"}, > "error_request",undefined,"Invalid login/pass"}} > ``` > > So, it seems i can't use any element in place of detail element or i do > something wrong. > > — > Reply to this email directly or view it on GitHub > https://github.com/willemdj/erlsom/issues/45#issuecomment-133826367.
lego12239 commented 9 years ago

So, with:

<xs:element name="detail" type="tns:detail" minOccurs="0" />

and with mixed="true" i get:

{ok,{'soap:Fault',[],
                  {qname,"http://schemas.xmlsoap.org/soap/envelope/","Server",
                         "SOAP-ENV","soap"},
                  "error_auth",undefined,
                  {'soap:detail',[],["Client not authorized"]}}}

and with:

<xs:element name="detail" type="xs:string" minOccurs="0" />

and without mixed="true" i get:

{ok,{'soap:Fault',[],
                  {qname,"http://schemas.xmlsoap.org/soap/envelope/","Server",
                         "SOAP-ENV","soap"},
                  "error_auth",undefined,"Client not authorized"}}

With mixed="true" the result looks more complicated, but it works!