一旦在模式招标的基础上构建xml,我就会对pyxb产生问题。
我发现,根据对一些简单(‘原子简单类型’)元素的值计算方法,我得到了不同类型的赋值。
我的意思是,我的细节是:
Python 2.7
PyXB版本1.2.5
操作系统: Windows 7
模式的一部分:
<xs:simpleType name="Max140Text_DE_customized">
<xs:restriction base="Max140Text">
<xs:minLength value="1"/>
<xs:maxLength value="140"/>
<xs:pattern value="[ ]*[A-Za-z0-9+?/:()\.,'\-][A-Za-z0-9+?/:()\.,' \-]*"/>
</xs:restriction>
</xs:simpleType> (...)
<xs:simpleType name="Max140Text">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="140"/>
</xs:restriction>
</xs:simpleType>最新情况:
使用Max140Text_DE_customized的架构元素
<xs:complexType name="PartyIdentification32_CH_pacs008">
<xs:complexContent>
<xs:restriction base="PartyIdentification32">
<xs:sequence>
<xs:element name="Nm" type="Max140Text_DE_customized" minOccurs="0"/>
<xs:element name="PstlAdr" type="PostalAddress6_customized" minOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>由pyxb生成的投标:
# Atomic simple type: {http://www.schema-uri/de/MySchema}Max140Text
class Max140Text (pyxb.binding.datatypes.string):
"""An atomic simple type."""
_ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Max140Text')
_XSDLocation = pyxb.utils.utility.Location('C:\\Python27\\Scripts\\MySchema.xsd', 1032, 2)
_Documentation = None
Max140Text._CF_minLength = pyxb.binding.facets.CF_minLength(value=pyxb.binding.datatypes.nonNegativeInteger(1))
Max140Text._CF_maxLength = pyxb.binding.facets.CF_maxLength(value=pyxb.binding.datatypes.nonNegativeInteger(140))
Max140Text._InitializeFacetMap(Max140Text._CF_minLength,
Max140Text._CF_maxLength)
Namespace.addCategoryObject('typeBinding', 'Max140Text', Max140Text)
_module_typeBindings.Max140Text = Max140Text
# Atomic simple type: {http://www.schema-uri/de/MySchema}Max140Text_DE_customized
class Max140Text_DE_customized (Max140Text):
"""An atomic simple type."""
_ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Max140Text_DE_customized')
_XSDLocation = pyxb.utils.utility.Location('C:\\Python27\\Scripts\\MySchema.xsd', 1038, 2)
_Documentation = None
Max140Text_DE_customized._CF_minLength = pyxb.binding.facets.CF_minLength(value=pyxb.binding.datatypes.nonNegativeInteger(1))
Max140Text_DE_customized._CF_pattern = pyxb.binding.facets.CF_pattern()
Max140Text_DE_customized._CF_pattern.addPattern(pattern="[ ]*[A-Za-z0-9+?/:()\\.,'\\-][A-Za-z0-9+?/:()\\.,' \\-]*")
Max140Text_DE_customized._CF_maxLength = pyxb.binding.facets.CF_maxLength(value=pyxb.binding.datatypes.nonNegativeInteger(140))
Max140Text_DE_customized._InitializeFacetMap(Max140Text_DE_customized._CF_minLength,
Max140Text_DE_customized._CF_pattern, Max140Text_DE_customized._CF_maxLength)
Namespace.addCategoryObject('typeBinding', 'Max140Text_DE_customized', Max140Text_DE_customized)
_module_typeBindings.Max140Text_DE_customized = Max140Text_DE_customized当我将值赋值给仅传递字符串的Max140Text_DE_customized类型(按模式)的复杂元素时,就会错误地识别该元素的类型。
这不会在生成文档后执行模式验证(由于类型错误)。
my_elem = myschema_biddings() # some complex element
my_elem.Nm = "Foo" # no pattern validation !
type(my_elem.Nm) = <class'myschema_bidddings.Max140Text'> # wrong
my_elem.Nm = myschema_biddings.Max140Text_DE_customized("Bar")
type(my_elem.Nm) = <class'myschema_bidddings.Max140Text_DE_customized'> # correct 发布于 2017-05-20 12:21:23
此行为是由于PyXB中的bug没有正确检测到您已重写了Nm的基类元素声明。
https://stackoverflow.com/questions/43890710
复制相似问题