我还没有找到一种方法来描述可重复原始类型的 xml 属性;到目前为止我最好的猜测:
class Contact(ComplexModel):
"contact person and communication channel"
contactName = primitive.Unicode(min_len=1, max_len=70, nillable=False)
channel = primitive.Unicode(max_occurs='unbounded')
channelCode = XmlAttribute(Enum('TELEPHONE', 'TELEFAX', 'EMAIL', 'WEBSITE', type_name='channelCode'), attribute_of='channel')
这会产生一个看起来正确的 wsdl(至少对我而言):
<xs:complexType name="Contact">
<xs:sequence>
<xs:element name="channel" minOccurs="0" maxOccurs="unbounded" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="channelCode" type="tns:channelCode"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="contactName" type="tns:Contact_contactNameType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
但我不知道如何使用 Contact 类!
>>> c = Contact()
>>> c.contactName = 'xxx'
>>> c.channel = [ '1', '2' ]
>>> # c.channelCode = ???