2017-05-10 56 views
0

我在基于模式出价构建xml时遇到了pyxb问题。
我发现,取决于赋值给一些简单的('原子简单类型')元素的方法,我得到不同的类型分配。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+?/:()\.,&apos;\-][A-Za-z0-9+?/:()\.,&apos; \-]*"/> 
    </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> 

更新:
使用模式元素:

<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 
+0

没有看到'myschema_biddings'类的模式,没有足够的信息来理解发生了什么。 – pabigot

回答

0

此行为是由于bug in PyXB不正确检测,你已经覆盖了基类元素声明Nm