我有一个描述电子发票结构的 xml 模式。我已经使用带有generateDS的模式来为该格式创建解析器。在解析发票时,它似乎工作正常,但是在任何类型的内容的部分,它会停止处理出现这些元素的子项。
描述任何元素的模式的一部分:
<!-- Elements to describe the invoice extensions -->
<xs:complexType name="ExtensionRecord">
<xs:sequence>
<xs:element name="InformationName" type="NormalTextType" minOccurs="0"/>
<xs:element name="InformationContent" type="LongTextType"/>
<xs:element name="CustomContent" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="extensionId" type="ShortTextType" use="optional"/>
</xs:complexType>
我使用解析器的实现的相关部分:
E_Invoice = einvoice111.parseString(xmlString, silence=True)
for ai in E_Invoice.Invoice.AdditionalInformation:
print(dir(ai) )
print(dir(ai.CustomContent))
print(ai.CustomContent.export(sys.stdout, 0, name_='CustomContent'))
部分有效载荷 XML:
<AdditionalInformation extensionId="invoicePDFFormat">
<InformationContent/>
<CustomContent>
<any>
<Content>JVBERi0xLjQ........
<BASE64 coded binary>
.....</Content>
和该代码的输出:
['CustomContent', 'InformationContent', 'InformationName', 'Tag_strip_pattern_', '_FixedOffsetTZ', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'build', 'buildAttributes', 'buildChildren', 'convert_unicode', 'export', 'exportAttributes', 'exportChildren', 'extensionId', 'factory', 'gds_build_any', 'gds_encode', 'gds_format_base64', 'gds_format_boolean', 'gds_format_boolean_list', 'gds_format_date', 'gds_format_datetime', 'gds_format_double', 'gds_format_double_list', 'gds_format_float', 'gds_format_float_list', 'gds_format_integer', 'gds_format_integer_list', 'gds_format_string', 'gds_format_time', 'gds_parse_date', 'gds_parse_datetime', 'gds_parse_time', 'gds_reverse_node_mapping', 'gds_str_lower', 'gds_validate_base64', 'gds_validate_boolean', 'gds_validate_boolean_list', 'gds_validate_date', 'gds_validate_datetime', 'gds_validate_double', 'gds_validate_double_list', 'gds_validate_float', 'gds_validate_float_list', 'gds_validate_integer', 'gds_validate_integer_list', 'gds_validate_simple_patterns', 'gds_validate_string', 'gds_validate_time', 'get_CustomContent', 'get_InformationContent', 'get_InformationName', 'get_class_obj_', 'get_extensionId', 'get_path_', 'get_path_list_', 'hasContent_', 'original_tagname_', 'set_CustomContent', 'set_InformationContent', 'set_InformationName', 'set_extensionId', 'subclass', 'superclass', 'tzoff_pattern', 'validate_LongTextType', 'validate_NormalTextType', 'validate_ShortTextType']
['Tag_strip_pattern_', '_FixedOffsetTZ', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'anytypeobjs_', 'build', 'buildAttributes', 'buildChildren', 'convert_unicode', 'export', 'exportAttributes', 'exportChildren', 'factory', 'gds_build_any', 'gds_encode', 'gds_format_base64', 'gds_format_boolean', 'gds_format_boolean_list', 'gds_format_date', 'gds_format_datetime', 'gds_format_double', 'gds_format_double_list', 'gds_format_float', 'gds_format_float_list', 'gds_format_integer', 'gds_format_integer_list', 'gds_format_string', 'gds_format_time', 'gds_parse_date', 'gds_parse_datetime', 'gds_parse_time', 'gds_reverse_node_mapping', 'gds_str_lower', 'gds_validate_base64', 'gds_validate_boolean', 'gds_validate_boolean_list', 'gds_validate_date', 'gds_validate_datetime', 'gds_validate_double', 'gds_validate_double_list', 'gds_validate_float', 'gds_validate_float_list', 'gds_validate_integer', 'gds_validate_integer_list', 'gds_validate_simple_patterns', 'gds_validate_string', 'gds_validate_time', 'get_anytypeobjs_', 'get_class_obj_', 'get_path_', 'get_path_list_', 'hasContent_', 'original_tagname_', 'set_anytypeobjs_', 'subclass', 'superclass', 'tzoff_pattern']
<CustomContent/>
CustomContent 有省略标签,表示对象结构到此结束。我也尝试过export()
整个文档,它也有同样的情况。
所以这是部分:
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip"/>
</xs:sequence>
</xs:complexType>
没有出现在 Python 对象树中。
当我查看与架构匹配的生成库时,CustomContent 类的相关部分:
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
obj_ = self.gds_build_any(child_, 'CustomContentType')
if obj_ is not None:
self.set_anytypeobjs_(obj_)
它使用gds_build_any()
方法,而不是创建从模式生成的新类实例(也不存在)。
使用 Suds 时,我可以访问任何元素及其内容,但它会在其他地方中断。
有没有办法配置 generateDS 以便它:
- 为所有模式的元素创建类?
- 将这些类用于整个文档?