willemdj / erlsom

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

'Type not found in hierarchy' when no type is defined and XSI type is given #81

Closed Awlexus closed 3 years ago

Awlexus commented 3 years ago

Given the following XSD (extracted from XAdES)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="SignedSignatureProperties" type="SignedSignaturePropertiesType"/>
    <xs:complexType name="SignedSignaturePropertiesType">
        <xs:sequence>
            <xs:element name="SigningTime" type="xs:dateTime" minOccurs="0"/>
            <xs:element name="SignaturePolicyIdentifier" type="SignaturePolicyIdentifierType" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="Id" type="xs:ID" use="optional"/>
    </xs:complexType>
    <xs:complexType name="SignaturePolicyIdentifierType">
        <xs:choice>
            <xs:element name="SignaturePolicyId" type="SignaturePolicyIdType"/>
            <xs:element name="SignaturePolicyImplied"/>
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="SignaturePolicyIdType">
        <xs:sequence>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="SPUserNoticeType">
        <xs:sequence>
            <xs:element name="NoticeRef" type="NoticeReferenceType" minOccurs="0"/>
            <xs:element name="ExplicitText" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="NoticeReferenceType">
        <xs:sequence>
            <xs:element name="Organization" type="xs:string"/>
            <xs:element name="NoticeNumbers" type="IntegerListType"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="IntegerListType">
        <xs:sequence>
            <xs:element name="int" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

And the following response

<xades:SignedSignatureProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#">
    <xades:SigningTime>2001-10-26T21:32:52+02:00</xades:SigningTime>
    <xades:SignaturePolicyIdentifier>
        <xades:SignaturePolicyImplied xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xades:SPUserNoticeType">
            <xades:ExplicitText>Advanced electronic signature</xades:ExplicitText>
        </xades:SignaturePolicyImplied>
    </xades:SignaturePolicyIdentifier>
</xades:SignedSignatureProperties>

You will get an error when scanning the response:

1> {ok, Model} = erlsom:compile_xsd_file("priv/example.xsd").
2> erlsom:scan_file("priv/response.xml", Model)
{error,[{exception,{error,"Type not found in hierarchy: SignaturePolicyIdentifierType-SignaturePolicyImplied"}},
        {stack,['SignaturePolicyIdentifierType',
                'SignedSignaturePropertiesType']},
        {received,{startElement,"http://uri.etsi.org/01903/v1.3.2#",
                                "SignaturePolicyImplied","xades",
                                [{attribute,"type","xsi",
                                            "http://www.w3.org/2001/XMLSchema-instance",
                                            "xades:SPUserNoticeType"}]}}]}

I was able to narrow the issue down to translateType not adding the type to the history, because it was not defined and findDerivedType therefore being unable to find the type as ancestor in the TypeHierarchy.

I'm not so familiar with XML-Schemas in general, but is this check necessary?

philipgiuliani commented 3 years ago

@willemdj did you have any time to look at this?

willemdj commented 3 years ago

No, I did not yet find the time. I will certainly look at it, but it may take some time, sorry.

philipgiuliani commented 3 years ago

Hi @willemdj, hope you are well! Could you maybe just give us a hint where we should look at to resolve this specific issue? Thanks!

willemdj commented 3 years ago

Hi,

I have been on vacation, but I did have a look before I left. I don’t think this is something that can be fixed easily. I do expect that I will be able to fix it, but I don’t have much time available so it may take some time.

In the mean time you might try to change the XSD to work around the problem.

Regards, Willem.

Op 1 sep. 2021 om 11:14 heeft Philip Giuliani @.***> het volgende geschreven:

Hi @willemdj, hope you are well! Could you maybe just give us a hint where we should look at to resolve this specific issue? Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

willemdj commented 3 years ago

It should work now...