xsd2php icon indicating copy to clipboard operation
xsd2php copied to clipboard

xs:Choice of xs:Sequence not supported?

Open rtek opened this issue 1 year ago • 2 comments

Attempting to parse this xsd results in a fatal. Is this an unsupported situation or a bug? Thoughts on a workaround?

https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd

<element name="PGPData" type="ds:PGPDataType"/> 
<complexType name="PGPDataType"> 
  <choice>
    <sequence>
      <element name="PGPKeyID" type="base64Binary"/> 
      <element name="PGPKeyPacket" type="base64Binary" minOccurs="0"/> 
      <any namespace="##other" processContents="lax" minOccurs="0"
       maxOccurs="unbounded"/>
    </sequence>
    <sequence>
      <element name="PGPKeyPacket" type="base64Binary"/> 
      <any namespace="##other" processContents="lax" minOccurs="0"
       maxOccurs="unbounded"/>
    </sequence>
  </choice>
</complexType>
PHP Fatal error:  Uncaught TypeError: GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter::visitElement(): Argument #3 ($element) must be of type GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle, GoetasWebservices\XML\XSDReader\Schema\Element\Sequence given, called in ...\vendor\goetas-webservices\xsd2php\src\Php\PhpConverter.php on line 133 and defined in ...\vendor\goetas-webservices\xsd2php\src\Php\PhpConverter.php:429

rtek avatar Feb 20 '24 20:02 rtek

I ran into the same issue with the that file after upgrading my php runtime from 7.4 to 8.2. Before php8 it was running flawless for over a year.

I spend some time debugging and made it work by patching some functions in Php/PhpConverter. Looks like the implementation of xs:sequence is just incomplete. Someone already created a pull request with a proper implementation which you could use a base for a patch until this fix is included in a release. https://github.com/goetas-webservices/xsd2php/pull/171/commits/bba3d457a584210321c45e33d5429b8a39cc6827

nikbobbie avatar Mar 27 '24 11:03 nikbobbie

As a workaround i just altered the XSD to drop the second sequence and remove the choice, since i didnt need it anyways - e.g.

<element name="PGPData" type="ds:PGPDataType"/> 
<complexType name="PGPDataType"> 
    <sequence>
      <element name="PGPKeyID" type="base64Binary"/> 
      <element name="PGPKeyPacket" type="base64Binary" minOccurs="0"/> 
      <any namespace="##other" processContents="lax" minOccurs="0"
       maxOccurs="unbounded"/>
    </sequence>
</complexType>

related https://github.com/goetas-webservices/xsd2php/issues/170

rtek avatar Mar 27 '24 15:03 rtek