0

I try to do my first steps with PyXB but have the problem, that I cannot create the element paket. I have gone through the samples but can't find any more information on how to handle this. If the abstract element is one level deeper there seems a solution, but here it is on top level.

Can somebody help me with this?

Creating classes

pyxbgen -u arelda_v4.xsd -m all
WARNING:pyxb.binding.generate:Complex type {http://bar.admin.ch/arelda/v4}paket renamed to paket_
Python for http://bar.admin.ch/arelda/v4 requires 1 modules

Try to create paket element:

Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import all
>>> paket = all.paket()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/pyxb/binding/basis.py", line 1600, in __call__
    rv = self.typeDefinition().Factory(*args, **kw)
  File "/usr/lib/python2.7/site-packages/pyxb/binding/basis.py", line 305, in Factory
    rv = cls._DynamicCreate(*args, **kw)
  File "/usr/lib/python2.7/site-packages/pyxb/binding/basis.py", line 677, in _DynamicCreate
    return ctor(*args, **kw)
  File "/usr/lib/python2.7/site-packages/pyxb/binding/basis.py", line 2075, in __init__
    raise pyxb.AbstractInstantiationError(type(self), location, dom_node)
pyxb.exceptions_.AbstractInstantiationError: Cannot instantiate abstract type {http://bar.admin.ch/arelda/v4}paket directly

XSD

<xs:element name="paket" type="paket">
    <xs:key name="ordnungssystempositionIdKey">
        <xs:annotation>
            <xs:documentation>Das Element id in der Entität Ordnungssystemposition muss eindeutig sein.</xs:documentation>
        </xs:annotation>
        <xs:selector xpath=".//arelda:ordnungssystemposition"/>
        <xs:field xpath="@id"/>
    </xs:key>
    <xs:key name="dossierIdKey">
        <xs:annotation>
            <xs:documentation>Das Element id in der Entität Dossier muss eindeutig sein.</xs:documentation>
        </xs:annotation>
        <xs:selector xpath=".//arelda:dossier"/>
        <xs:field xpath="@id"/>
    </xs:key>
    <xs:key name="dokumentIdKey">
        <xs:annotation>
            <xs:documentation>Das Element id in der Entität Dokument muss eindeutig sein.</xs:documentation>
        </xs:annotation>
        <xs:selector xpath=".//arelda:dokument"/>
        <xs:field xpath="@id"/>
    </xs:key>
    <xs:key name="archivischeNotizIdKey">
        <xs:annotation>
            <xs:documentation>Das Element id in der Entität ArchivischeNotiz muss eindeutig sein.</xs:documentation>
        </xs:annotation>
        <xs:selector xpath=".//arelda:archivischeNotiz"/>
        <xs:field xpath="@id"/>
    </xs:key>
</xs:element>

<xs:complexType name="paket" abstract="true">

XML

<?xml version="1.0" encoding="UTF-8"?>
<v4:paket schemaVersion="4.0" xsi:type="v4:paketSIP" xmlns:v4="http://bar.admin.ch/arelda/v4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <v4:paketTyp>SIP</v4:paketTyp>
</v4:paket>

Thanks Manuel

MAGYS
  • 181
  • 1
  • 14

1 Answers1

2

The type paket is abstract, but this type is used in an element declaration against which the v4:paket element is validated. This is not allowed for abstract types. Abstract types can only be derived, and their concrete derived type used for validation.

If you have control over the XSD document, setting abstract to false, or omitting this attribute, should make the error go away.

<xs:complexType name="paket" abstract="false">
  ...
</xs:complexType>
Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37