2016-08-09 173 views
0

我嘗試使用PyXB完成我的第一步,但遇到問題,無法創建元素分段。我已經通過了樣本,但找不到更多關於如何處理這個問題的信息。如果抽象元素更深一層,似乎有一個解決方案,但這裏是最高層。PyXB:無法實例化抽象類型

有人可以幫助我嗎?

創建類

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 

嘗試創建的一攬子貸款元素:

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> 

由於 曼努埃爾

回答

1

類型一攬子貸款是抽象的,但是這種類型的在抵靠該V4的元素聲明使用:一攬子貸款元件被驗證。這不適用於抽象類型。只能派生抽象類型,並使用它們用於驗證的具體派生類型。

如果你有過XSD文件控制,設置抽象,或省略此屬性,應該讓錯誤消失。

<xs:complexType name="paket" abstract="false"> 
    ... 
</xs:complexType> 
相關問題