Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected event, expected end-tag #96

Open
larshesel opened this issue Jan 9, 2025 · 1 comment · May be fixed by #97
Open

Unexpected event, expected end-tag #96

larshesel opened this issue Jan 9, 2025 · 1 comment · May be fixed by #97

Comments

@larshesel
Copy link

larshesel commented Jan 9, 2025

Hi

I've been trying figure out why an XML doesn't validate against an XSD for a while now. I've tried to minimize the XSD and XML as much as possible while still getting the error. The XML validates against the XSD on the following sites: https://www.freeformatter.com/xml-validator-xsd.html and https://www.liquid-technologies.com/online-xsd-validator which makes me think there might be either some super strange thing I'm overlooking int the XSD or perhaps an issue in erlsom.

To reproduce I use the following XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
	   xmlns="http://example.com"
	   targetNamespace="http://example.com" elementFormDefault="unqualified"
	   attributeFormDefault="unqualified">
  <xs:element name="L1">
    <xs:complexType>
      <xs:choice>
	<xs:sequence>
	  <xs:element name="E_MAIL" minOccurs="0" maxOccurs="unbounded">
	    <xs:complexType>
	      <xs:sequence>
		<xs:element name="TEXT" type="xs:string" />
	      </xs:sequence>
	    </xs:complexType>
	  </xs:element>
	</xs:sequence>
	
	<xs:sequence>
          <xs:element name="FLAG" type="xs:boolean" fixed="true" minOccurs="0" />
	</xs:sequence>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

and the following xml:

<ns:L1 xmlns:ns="http://example.com">
  <E_MAIL>
    <TEXT>text</TEXT>
  </E_MAIL>
</ns:L1>

The error I get by running:

    response = File.read!("./test/response_min.xml")
    xsd = File.read!("./test/xsd.xsd")
    {:ok, model} = :erlsom.compile(xsd)
    {:ok, _data, _} = :erlsom.scan(response, model)

is

no match of right hand side value: {:error, [exception: {:error, {~c"2 - Unexpected event, expected end-tag"}}, stack: [:"p:L1"], received: {:startElement, [], ~c"E_MAIL", [], []}]}

Note, if I remove the second sequence in the choice node or simply swap the two sequences in the choice node, the XML validates.

If there's indeed an issue with Erlsom I'll be happy to try and help resolve it.

Kind regards,
Lars

@larshesel larshesel changed the title Unexpected end tag Unexpected event, expected end-tag Jan 9, 2025
@willemdj
Copy link
Owner

willemdj commented Jan 9, 2025

I think that there is indeed a bug. Something seems to go wrong with a choice between 2 sequences. It must be a relatively rare thing... But I think it is valid.

This is a problem with the construction of the "Model" (the translation of the XSD to an internal data structure that describes the structure of the valid XML documents). There could be more problems, if this requires a change to the Model, but I don't anticipate that. If you can work out what needs to be changed that would be great, but the code is fairly complex and also a bit messy, I am afraid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants