I have an xml schema that describes e-invoice structure. I've used schema with generateDS to create a parser for that format. When parsing an invoice, it seems to work fine, but a section where is any-typed content, it stops processing childs where those elements appear.
Part of the schema that describes any element:
<!-- 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>
Relevant part of my implementation that uses the parser:
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'))
Part of payload XML:
<AdditionalInformation extensionId="invoicePDFFormat">
<InformationContent/>
<CustomContent>
<any>
<Content>JVBERi0xLjQ........
<BASE64 coded binary>
.....</Content>
and output of that code:
['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 has omittag, showing that object structure ends there. I've also tried to export()
whole document and it has the same situation.
So it's the part:
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip"/>
</xs:sequence>
</xs:complexType>
that does not appear in Python object-tree.
When I look into generated library that matches the schema, relevant part of the CustomContent class:
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
obj_ = self.gds_build_any(child_, 'CustomContentType')
if obj_ is not None:
self.set_anytypeobjs_(obj_)
It uses gds_build_any()
method, instead of creating a new instance of class that it would have generated from schema (that doesn't exist either).
When using Suds, I can access the any element and its content, but it breaks elsewhere.
Is there a way to configure generateDS so that it would:
- create classes to all schema's elements?
- use those classes to whole document?