#!/usr/bin/env python
# -*- coding: utf-8 -*-

###
# Copyright 2014 Code Master Oy (http://www.codemaster.fi/)
#
# This file is part of py-finvoice.
#
# py-finvoice is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# py-finvoice is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with py-finvoice. If not, see <http://www.gnu.org/licenses/>.
##

import sys
import getopt
import re as re_
import base64
import datetime as datetime_

etree_ = None
Verbose_import_ = False
(
    XMLParser_import_none, XMLParser_import_lxml,
    XMLParser_import_elementtree
) = range(3)
XMLParser_import_library = None
try:
    # lxml
    from lxml import etree as etree_
    XMLParser_import_library = XMLParser_import_lxml
    if Verbose_import_:
        print("running with lxml.etree")
except ImportError:
    try:
        # cElementTree from Python 2.5+
        import xml.etree.cElementTree as etree_
        XMLParser_import_library = XMLParser_import_elementtree
        if Verbose_import_:
            print("running with cElementTree on Python 2.5+")
    except ImportError:
        try:
            # ElementTree from Python 2.5+
            import xml.etree.ElementTree as etree_
            XMLParser_import_library = XMLParser_import_elementtree
            if Verbose_import_:
                print("running with ElementTree on Python 2.5+")
        except ImportError:
            try:
                # normal cElementTree install
                import cElementTree as etree_
                XMLParser_import_library = XMLParser_import_elementtree
                if Verbose_import_:
                    print("running with cElementTree")
            except ImportError:
                try:
                    # normal ElementTree install
                    import elementtree.ElementTree as etree_
                    XMLParser_import_library = XMLParser_import_elementtree
                    if Verbose_import_:
                        print("running with ElementTree")
                except ImportError:
                    raise ImportError(
                        "Failed to import ElementTree from any known place")


def parsexml_(*args, **kwargs):
    if (XMLParser_import_library == XMLParser_import_lxml and
            'parser' not in kwargs):
        # Use the lxml ElementTree compatible parser so that, e.g.,
        #   we ignore comments.
        kwargs['parser'] = etree_.ETCompatXMLParser()
    doc = etree_.parse(*args, **kwargs)
    return doc

#
# User methods
#
# Calls to the methods in these classes are generated by generateDS.py.
# You can replace these methods by re-implementing the following class
#   in a module named generatedssuper.py.

try:
    from generatedssuper import GeneratedsSuper
except ImportError, exp:

    class GeneratedsSuper(object):
        tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$')
        class _FixedOffsetTZ(datetime_.tzinfo):
            def __init__(self, offset, name):
                self.__offset = datetime_.timedelta(minutes=offset)
                self.__name = name
            def utcoffset(self, dt):
                return self.__offset
            def tzname(self, dt):
                return self.__name
            def dst(self, dt):
                return None
        def gds_format_string(self, input_data, input_name=''):
            return input_data
        def gds_validate_string(self, input_data, node, input_name=''):
            if not input_data:
                return ''
            else:
                return input_data
        def gds_format_base64(self, input_data, input_name=''):
            return base64.b64encode(input_data)
        def gds_validate_base64(self, input_data, node, input_name=''):
            return input_data
        def gds_format_integer(self, input_data, input_name=''):
            return '%d' % input_data
        def gds_validate_integer(self, input_data, node, input_name=''):
            return input_data
        def gds_format_integer_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_integer_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    float(value)
                except (TypeError, ValueError):
                    raise_parse_error(node, 'Requires sequence of integers')
            return input_data
        def gds_format_float(self, input_data, input_name=''):
            return ('%.15f' % input_data).rstrip('0')
        def gds_validate_float(self, input_data, node, input_name=''):
            return input_data
        def gds_format_float_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_float_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    float(value)
                except (TypeError, ValueError):
                    raise_parse_error(node, 'Requires sequence of floats')
            return input_data
        def gds_format_double(self, input_data, input_name=''):
            return '%e' % input_data
        def gds_validate_double(self, input_data, node, input_name=''):
            return input_data
        def gds_format_double_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_double_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                try:
                    float(value)
                except (TypeError, ValueError):
                    raise_parse_error(node, 'Requires sequence of doubles')
            return input_data
        def gds_format_boolean(self, input_data, input_name=''):
            return ('%s' % input_data).lower()
        def gds_validate_boolean(self, input_data, node, input_name=''):
            return input_data
        def gds_format_boolean_list(self, input_data, input_name=''):
            return '%s' % input_data
        def gds_validate_boolean_list(self, input_data, node, input_name=''):
            values = input_data.split()
            for value in values:
                if value not in ('true', '1', 'false', '0', ):
                    raise_parse_error(
                        node,
                        'Requires sequence of booleans '
                        '("true", "1", "false", "0")')
            return input_data
        def gds_validate_datetime(self, input_data, node, input_name=''):
            return input_data
        def gds_format_datetime(self, input_data, input_name=''):
            if input_data.microsecond == 0:
                _svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % (
                    input_data.year,
                    input_data.month,
                    input_data.day,
                    input_data.hour,
                    input_data.minute,
                    input_data.second,
                )
            else:
                _svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % (
                    input_data.year,
                    input_data.month,
                    input_data.day,
                    input_data.hour,
                    input_data.minute,
                    input_data.second,
                    ('%f' % (float(input_data.microsecond) / 1000000))[2:],
                )
            if input_data.tzinfo is not None:
                tzoff = input_data.tzinfo.utcoffset(input_data)
                if tzoff is not None:
                    total_seconds = tzoff.seconds + (86400 * tzoff.days)
                    if total_seconds == 0:
                        _svalue += 'Z'
                    else:
                        if total_seconds < 0:
                            _svalue += '-'
                            total_seconds *= -1
                        else:
                            _svalue += '+'
                        hours = total_seconds // 3600
                        minutes = (total_seconds - (hours * 3600)) // 60
                        _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
            return _svalue
        @classmethod
        def gds_parse_datetime(cls, input_data):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            time_parts = input_data.split('.')
            if len(time_parts) > 1:
                micro_seconds = int(float('0.' + time_parts[1]) * 1000000)
                input_data = '%s.%s' % (time_parts[0], micro_seconds, )
                dt = datetime_.datetime.strptime(
                    input_data, '%Y-%m-%dT%H:%M:%S.%f')
            else:
                dt = datetime_.datetime.strptime(
                    input_data, '%Y-%m-%dT%H:%M:%S')
            dt = dt.replace(tzinfo=tz)
            return dt
        def gds_validate_date(self, input_data, node, input_name=''):
            return input_data
        def gds_format_date(self, input_data, input_name=''):
            _svalue = '%04d-%02d-%02d' % (
                input_data.year,
                input_data.month,
                input_data.day,
            )
            try:
                if input_data.tzinfo is not None:
                    tzoff = input_data.tzinfo.utcoffset(input_data)
                    if tzoff is not None:
                        total_seconds = tzoff.seconds + (86400 * tzoff.days)
                        if total_seconds == 0:
                            _svalue += 'Z'
                        else:
                            if total_seconds < 0:
                                _svalue += '-'
                                total_seconds *= -1
                            else:
                                _svalue += '+'
                            hours = total_seconds // 3600
                            minutes = (total_seconds - (hours * 3600)) // 60
                            _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
            except AttributeError:
                pass
            return _svalue
        @classmethod
        def gds_parse_date(cls, input_data):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            dt = datetime_.datetime.strptime(input_data, '%Y-%m-%d')
            dt = dt.replace(tzinfo=tz)
            return dt.date()
        def gds_validate_time(self, input_data, node, input_name=''):
            return input_data
        def gds_format_time(self, input_data, input_name=''):
            if input_data.microsecond == 0:
                _svalue = '%02d:%02d:%02d' % (
                    input_data.hour,
                    input_data.minute,
                    input_data.second,
                )
            else:
                _svalue = '%02d:%02d:%02d.%s' % (
                    input_data.hour,
                    input_data.minute,
                    input_data.second,
                    ('%f' % (float(input_data.microsecond) / 1000000))[2:],
                )
            if input_data.tzinfo is not None:
                tzoff = input_data.tzinfo.utcoffset(input_data)
                if tzoff is not None:
                    total_seconds = tzoff.seconds + (86400 * tzoff.days)
                    if total_seconds == 0:
                        _svalue += 'Z'
                    else:
                        if total_seconds < 0:
                            _svalue += '-'
                            total_seconds *= -1
                        else:
                            _svalue += '+'
                        hours = total_seconds // 3600
                        minutes = (total_seconds - (hours * 3600)) // 60
                        _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
            return _svalue
        @classmethod
        def gds_parse_time(cls, input_data):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            if len(input_data.split('.')) > 1:
                dt = datetime_.datetime.strptime(input_data, '%H:%M:%S.%f')
            else:
                dt = datetime_.datetime.strptime(input_data, '%H:%M:%S')
            dt = dt.replace(tzinfo=tz)
            return dt.time()
        def gds_str_lower(self, instring):
            return instring.lower()
        def get_path_(self, node):
            path_list = []
            self.get_path_list_(node, path_list)
            path_list.reverse()
            path = '/'.join(path_list)
            return path
        Tag_strip_pattern_ = re_.compile(r'\{.*\}')
        def get_path_list_(self, node, path_list):
            if node is None:
                return
            tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
            if tag:
                path_list.append(tag)
            self.get_path_list_(node.getparent(), path_list)
        def get_class_obj_(self, node, default_class=None):
            class_obj1 = default_class
            if 'xsi' in node.nsmap:
                classname = node.get('{%s}type' % node.nsmap['xsi'])
                if classname is not None:
                    names = classname.split(':')
                    if len(names) == 2:
                        classname = names[1]
                    class_obj2 = globals().get(classname)
                    if class_obj2 is not None:
                        class_obj1 = class_obj2
            return class_obj1
        def gds_build_any(self, node, type_name=None):
            return None
        @classmethod
        def gds_reverse_node_mapping(cls, mapping):
            return dict(((v, k) for k, v in mapping.iteritems()))


#
# If you have installed IPython you can uncomment and use the following.
# IPython is available from http://ipython.scipy.org/.
#

## from IPython.Shell import IPShellEmbed
## args = ''
## ipshell = IPShellEmbed(args,
##     banner = 'Dropping into IPython',
##     exit_msg = 'Leaving Interpreter, back to program.')

# Then use the following line where and when you want to drop into the
# IPython shell:
#    ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')

#
# Globals
#

ExternalEncoding = 'ascii'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')

#
# Support/utility functions.
#


def showIndent(outfile, level, pretty_print=True):
    if pretty_print:
        for idx in range(level):
            continue
            # outfile.write('    ')


def quote_xml(inStr):
    if not inStr:
        return ''
    s1 = (isinstance(inStr, basestring) and inStr or
          '%s' % inStr)
    s1 = s1.replace('&', '&amp;')
    s1 = s1.replace('<', '&lt;')
    s1 = s1.replace('>', '&gt;')
    return s1


def quote_attrib(inStr):
    s1 = (isinstance(inStr, basestring) and inStr or
          '%s' % inStr)
    s1 = s1.replace('&', '&amp;')
    s1 = s1.replace('<', '&lt;')
    s1 = s1.replace('>', '&gt;')
    if '"' in s1:
        if "'" in s1:
            s1 = '"%s"' % s1.replace('"', "&quot;")
        else:
            s1 = "'%s'" % s1
    else:
        s1 = '"%s"' % s1
    return s1


def quote_python(inStr):
    s1 = inStr
    if s1.find("'") == -1:
        if s1.find('\n') == -1:
            return "'%s'" % s1
        else:
            return "'''%s'''" % s1
    else:
        if s1.find('"') != -1:
            s1 = s1.replace('"', '\\"')
        if s1.find('\n') == -1:
            return '"%s"' % s1
        else:
            return '"""%s"""' % s1


def get_all_text_(node):
    if node.text is not None:
        text = node.text
    else:
        text = ''
    for child in node:
        if child.tail is not None:
            text += child.tail
    return text


def find_attr_value_(attr_name, node):
    attrs = node.attrib
    attr_parts = attr_name.split(':')
    value = None
    if len(attr_parts) == 1:
        value = attrs.get(attr_name)
    elif len(attr_parts) == 2:
        prefix, name = attr_parts
        namespace = node.nsmap.get(prefix)
        if namespace is not None:
            value = attrs.get('{%s}%s' % (namespace, name, ))
    return value


class GDSParseError(Exception):
    pass


def raise_parse_error(node, msg):
    if XMLParser_import_library == XMLParser_import_lxml:
        msg = '%s (element %s/line %d)' % (
            msg, node.tag, node.sourceline, )
    else:
        msg = '%s (element %s)' % (msg, node.tag, )
    raise GDSParseError(msg)


class MixedContainer:
    # Constants for category:
    CategoryNone = 0
    CategoryText = 1
    CategorySimple = 2
    CategoryComplex = 3
    # Constants for content_type:
    TypeNone = 0
    TypeText = 1
    TypeString = 2
    TypeInteger = 3
    TypeFloat = 4
    TypeDecimal = 5
    TypeDouble = 6
    TypeBoolean = 7
    TypeBase64 = 8
    def __init__(self, category, content_type, name, value):
        self.category = category
        self.content_type = content_type
        self.name = name
        self.value = value
    def getCategory(self):
        return self.category
    def getContenttype(self, content_type):
        return self.content_type
    def getValue(self):
        return self.value
    def getName(self):
        return self.name
    def export(self, outfile, level, name, namespace, pretty_print=True):
        if self.category == MixedContainer.CategoryText:
            # Prevent exporting empty content as empty lines.
            if self.value.strip():
                outfile.write(self.value)
        elif self.category == MixedContainer.CategorySimple:
            self.exportSimple(outfile, level, name)
        else:    # category == MixedContainer.CategoryComplex
            self.value.export(outfile, level, namespace, name, pretty_print)
    def exportSimple(self, outfile, level, name):
        if self.content_type == MixedContainer.TypeString:
            outfile.write('<%s>%s</%s>' % (
                self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeInteger or \
                self.content_type == MixedContainer.TypeBoolean:
            outfile.write('<%s>%d</%s>' % (
                self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeFloat or \
                self.content_type == MixedContainer.TypeDecimal:
            outfile.write('<%s>%f</%s>' % (
                self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeDouble:
            outfile.write('<%s>%g</%s>' % (
                self.name, self.value, self.name))
        elif self.content_type == MixedContainer.TypeBase64:
            outfile.write('<%s>%s</%s>' % (
                self.name, base64.b64encode(self.value), self.name))
    def to_etree(self, element):
        if self.category == MixedContainer.CategoryText:
            # Prevent exporting empty content as empty lines.
            if self.value.strip():
                if len(element) > 0:
                    if element[-1].tail is None:
                        element[-1].tail = self.value
                    else:
                        element[-1].tail += self.value
                else:
                    if element.text is None:
                        element.text = self.value
                    else:
                        element.text += self.value
        elif self.category == MixedContainer.CategorySimple:
            subelement = etree_.SubElement(element, '%s' % self.name)
            subelement.text = self.to_etree_simple()
        else:    # category == MixedContainer.CategoryComplex
            self.value.to_etree(element)
    def to_etree_simple(self):
        if self.content_type == MixedContainer.TypeString:
            text = self.value
        elif (self.content_type == MixedContainer.TypeInteger or
                self.content_type == MixedContainer.TypeBoolean):
            text = '%d' % self.value
        elif (self.content_type == MixedContainer.TypeFloat or
                self.content_type == MixedContainer.TypeDecimal):
            text = '%f' % self.value
        elif self.content_type == MixedContainer.TypeDouble:
            text = '%g' % self.value
        elif self.content_type == MixedContainer.TypeBase64:
            text = '%s' % base64.b64encode(self.value)
        return text
    def exportLiteral(self, outfile, level, name):
        if self.category == MixedContainer.CategoryText:
            showIndent(outfile, level)
            outfile.write(
                'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % (
                    self.category, self.content_type, self.name, self.value))
        elif self.category == MixedContainer.CategorySimple:
            showIndent(outfile, level)
            outfile.write(
                'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % (
                    self.category, self.content_type, self.name, self.value))
        else:    # category == MixedContainer.CategoryComplex
            showIndent(outfile, level)
            outfile.write(
                'model_.MixedContainer(%d, %d, "%s",\n' % (
                    self.category, self.content_type, self.name,))
            self.value.exportLiteral(outfile, level + 1)
            showIndent(outfile, level)
            outfile.write(')\n')


class MemberSpec_(object):
    def __init__(self, name='', data_type='', container=0):
        self.name = name
        self.data_type = data_type
        self.container = container
    def set_name(self, name): self.name = name
    def get_name(self): return self.name
    def set_data_type(self, data_type): self.data_type = data_type
    def get_data_type_chain(self): return self.data_type
    def get_data_type(self):
        if isinstance(self.data_type, list):
            if len(self.data_type) > 0:
                return self.data_type[-1]
            else:
                return 'xs:string'
        else:
            return self.data_type
    def set_container(self, container): self.container = container
    def get_container(self): return self.container


def _cast(typ, value):
    if typ is None or value is None:
        return value
    return typ(value)

#
# Data representation classes.
#


class Finvoiceack(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Version=None, Acknowledgement=None, RefToCounterpartMessage=None, MessageTransmissionDetails=None, Error=None):
        self.original_tagname_ = None
        self.Version = _cast(None, Version)
        self.Acknowledgement = Acknowledgement
        self.RefToCounterpartMessage = RefToCounterpartMessage
        self.MessageTransmissionDetails = MessageTransmissionDetails
        if Error is None:
            self.Error = []
        else:
            self.Error = Error
    def factory(*args_, **kwargs_):
        if Finvoiceack.subclass:
            return Finvoiceack.subclass(*args_, **kwargs_)
        else:
            return Finvoiceack(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Acknowledgement(self): return self.Acknowledgement
    def set_Acknowledgement(self, Acknowledgement): self.Acknowledgement = Acknowledgement
    def get_RefToCounterpartMessage(self): return self.RefToCounterpartMessage
    def set_RefToCounterpartMessage(self, RefToCounterpartMessage): self.RefToCounterpartMessage = RefToCounterpartMessage
    def get_MessageTransmissionDetails(self): return self.MessageTransmissionDetails
    def set_MessageTransmissionDetails(self, MessageTransmissionDetails): self.MessageTransmissionDetails = MessageTransmissionDetails
    def get_Error(self): return self.Error
    def set_Error(self, Error): self.Error = Error
    def add_Error(self, value): self.Error.append(value)
    def insert_Error_at(self, index, value): self.Error.insert(index, value)
    def replace_Error_at(self, index, value): self.Error[index] = value
    def get_Version(self): return self.Version
    def set_Version(self, Version): self.Version = Version
    def validate_genericStringType2_61(self, value):
        # Validate type genericStringType2_61, a restriction on xs:string.
        pass
    def hasContent_(self):
        if (
            self.Acknowledgement is not None or
            self.RefToCounterpartMessage is not None or
            self.MessageTransmissionDetails is not None or
            self.Error
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='Finvoiceack', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='Finvoiceack')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='Finvoiceack', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='Finvoiceack'):
        if self.Version is not None and 'Version' not in already_processed:
            already_processed.add('Version')
            outfile.write(' Version=%s' % (self.gds_format_string(quote_attrib(self.Version).encode(ExternalEncoding), input_name='Version'), ))
    def exportChildren(self, outfile, level, namespace_='', name_='Finvoiceack', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Acknowledgement is not None:
            self.Acknowledgement.export(outfile, level, namespace_, name_='Acknowledgement', pretty_print=pretty_print)
        if self.RefToCounterpartMessage is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sRefToCounterpartMessage>%s</%sRefToCounterpartMessage>%s' % (namespace_, self.gds_format_string(quote_xml(self.RefToCounterpartMessage).encode(ExternalEncoding), input_name='RefToCounterpartMessage'), namespace_, eol_))
        if self.MessageTransmissionDetails is not None:
            self.MessageTransmissionDetails.export(outfile, level, namespace_, name_='MessageTransmissionDetails', pretty_print=pretty_print)
        for Error_ in self.Error:
            Error_.export(outfile, level, namespace_, name_='Error', pretty_print=pretty_print)
    def exportLiteral(self, outfile, level, name_='Finvoiceack'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        if self.Version is not None and 'Version' not in already_processed:
            already_processed.add('Version')
            showIndent(outfile, level)
            outfile.write('Version="%s",\n' % (self.Version,))
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Acknowledgement is not None:
            showIndent(outfile, level)
            outfile.write('Acknowledgement=model_.AcknowledgementType(\n')
            self.Acknowledgement.exportLiteral(outfile, level, name_='Acknowledgement')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.RefToCounterpartMessage is not None:
            showIndent(outfile, level)
            outfile.write('RefToCounterpartMessage=%s,\n' % quote_python(self.RefToCounterpartMessage).encode(ExternalEncoding))
        if self.MessageTransmissionDetails is not None:
            showIndent(outfile, level)
            outfile.write('MessageTransmissionDetails=model_.MessageTransmissionDetailsType(\n')
            self.MessageTransmissionDetails.exportLiteral(outfile, level, name_='MessageTransmissionDetails')
            showIndent(outfile, level)
            outfile.write('),\n')
        showIndent(outfile, level)
        outfile.write('Error=[\n')
        level += 1
        for Error_ in self.Error:
            showIndent(outfile, level)
            outfile.write('model_.ErrorType(\n')
            Error_.exportLiteral(outfile, level, name_='ErrorType')
            showIndent(outfile, level)
            outfile.write('),\n')
        level -= 1
        showIndent(outfile, level)
        outfile.write('],\n')
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        value = find_attr_value_('Version', node)
        if value is not None and 'Version' not in already_processed:
            already_processed.add('Version')
            self.Version = value
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Acknowledgement':
            obj_ = AcknowledgementType.factory()
            obj_.build(child_)
            self.Acknowledgement = obj_
            obj_.original_tagname_ = 'Acknowledgement'
        elif nodeName_ == 'RefToCounterpartMessage':
            RefToCounterpartMessage_ = child_.text
            RefToCounterpartMessage_ = self.gds_validate_string(RefToCounterpartMessage_, node, 'RefToCounterpartMessage')
            self.RefToCounterpartMessage = RefToCounterpartMessage_
            self.validate_genericStringType2_61(self.RefToCounterpartMessage)    # validate type genericStringType2_61
        elif nodeName_ == 'MessageTransmissionDetails':
            obj_ = MessageTransmissionDetailsType.factory()
            obj_.build(child_)
            self.MessageTransmissionDetails = obj_
            obj_.original_tagname_ = 'MessageTransmissionDetails'
        elif nodeName_ == 'Error':
            obj_ = ErrorType.factory()
            obj_.build(child_)
            self.Error.append(obj_)
            obj_.original_tagname_ = 'Error'
# end class Finvoiceack


class MessageData(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, MessageId=None, Timestamp=None):
        self.original_tagname_ = None
        self.MessageId = MessageId
        self.Timestamp = Timestamp
    def factory(*args_, **kwargs_):
        if MessageData.subclass:
            return MessageData.subclass(*args_, **kwargs_)
        else:
            return MessageData(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_MessageId(self): return self.MessageId
    def set_MessageId(self, MessageId): self.MessageId = MessageId
    def get_Timestamp(self): return self.Timestamp
    def set_Timestamp(self, Timestamp): self.Timestamp = Timestamp
    def hasContent_(self):
        if (
            self.MessageId is not None or
            self.Timestamp is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='MessageData', namespacedef_=' xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" ', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='MessageData')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='MessageData', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MessageData'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='MessageData', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.MessageId is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sMessageId>%s</%sMessageId>%s' % ('eb:', self.gds_format_string(quote_xml(self.MessageId).encode(ExternalEncoding), input_name='MessageId'), 'eb:', eol_))
        if self.Timestamp is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sTimestamp>%s</%sTimestamp>%s' % ('eb:', self.gds_format_string(quote_xml(self.Timestamp).encode(ExternalEncoding), input_name='Timestamp'), 'eb:', eol_))
    def exportLiteral(self, outfile, level, name_='MessageData'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.MessageId is not None:
            showIndent(outfile, level)
            outfile.write('MessageId=%s,\n' % quote_python(self.MessageId).encode(ExternalEncoding))
        if self.Timestamp is not None:
            showIndent(outfile, level)
            outfile.write('Timestamp=%s,\n' % quote_python(self.Timestamp).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'MessageId':
            MessageId_ = child_.text
            MessageId_ = self.gds_validate_string(MessageId_, node, 'MessageId')
            self.MessageId = MessageId_
        elif nodeName_ == 'Timestamp':
            Timestamp_ = child_.text
            Timestamp_ = self.gds_validate_string(Timestamp_, node, 'Timestamp')
            self.Timestamp = Timestamp_
# end class MessageData


class Reason(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Code=None, Text=None):
        self.original_tagname_ = None
        self.Code = Code
        if Text is None:
            self.Text = []
        else:
            self.Text = Text
    def factory(*args_, **kwargs_):
        if Reason.subclass:
            return Reason.subclass(*args_, **kwargs_)
        else:
            return Reason(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Code(self): return self.Code
    def set_Code(self, Code): self.Code = Code
    def get_Text(self): return self.Text
    def set_Text(self, Text): self.Text = Text
    def add_Text(self, value): self.Text.append(value)
    def insert_Text_at(self, index, value): self.Text.insert(index, value)
    def replace_Text_at(self, index, value): self.Text[index] = value
    def hasContent_(self):
        if (
            self.Code is not None or
            self.Text
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='Reason', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='Reason')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='Reason', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='Reason'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='Reason', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Code is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sCode>%s</%sCode>%s' % (namespace_, self.gds_format_integer(self.Code, input_name='Code'), namespace_, eol_))
        for Text_ in self.Text:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sText>%s</%sText>%s' % (namespace_, self.gds_format_string(quote_xml(Text_).encode(ExternalEncoding), input_name='Text'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='Reason'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Code is not None:
            showIndent(outfile, level)
            outfile.write('Code=%d,\n' % self.Code)
        showIndent(outfile, level)
        outfile.write('Text=[\n')
        level += 1
        for Text_ in self.Text:
            showIndent(outfile, level)
            outfile.write('%s,\n' % quote_python(Text_).encode(ExternalEncoding))
        level -= 1
        showIndent(outfile, level)
        outfile.write('],\n')
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Code':
            sval_ = child_.text
            try:
                ival_ = int(sval_)
            except (TypeError, ValueError), exp:
                raise_parse_error(child_, 'requires integer: %s' % exp)
            ival_ = self.gds_validate_integer(ival_, node, 'Code')
            self.Code = ival_
        elif nodeName_ == 'Text':
            Text_ = child_.text
            Text_ = self.gds_validate_string(Text_, node, 'Text')
            self.Text.append(Text_)
# end class Reason


class MessageTransmissionDetailsType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, MessageSenderDetails=None, MessageReceiverDetails=None, MessageDetails=None):
        self.original_tagname_ = None
        self.MessageSenderDetails = MessageSenderDetails
        self.MessageReceiverDetails = MessageReceiverDetails
        self.MessageDetails = MessageDetails
    def factory(*args_, **kwargs_):
        if MessageTransmissionDetailsType.subclass:
            return MessageTransmissionDetailsType.subclass(*args_, **kwargs_)
        else:
            return MessageTransmissionDetailsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_MessageSenderDetails(self): return self.MessageSenderDetails
    def set_MessageSenderDetails(self, MessageSenderDetails): self.MessageSenderDetails = MessageSenderDetails
    def get_MessageReceiverDetails(self): return self.MessageReceiverDetails
    def set_MessageReceiverDetails(self, MessageReceiverDetails): self.MessageReceiverDetails = MessageReceiverDetails
    def get_MessageDetails(self): return self.MessageDetails
    def set_MessageDetails(self, MessageDetails): self.MessageDetails = MessageDetails
    def hasContent_(self):
        if (
            self.MessageSenderDetails is not None or
            self.MessageReceiverDetails is not None or
            self.MessageDetails is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='MessageTransmissionDetailsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='MessageTransmissionDetailsType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='MessageTransmissionDetailsType', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MessageTransmissionDetailsType'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='MessageTransmissionDetailsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.MessageSenderDetails is not None:
            self.MessageSenderDetails.export(outfile, level, namespace_, name_='MessageSenderDetails', pretty_print=pretty_print)
        if self.MessageReceiverDetails is not None:
            self.MessageReceiverDetails.export(outfile, level, namespace_, name_='MessageReceiverDetails', pretty_print=pretty_print)
        if self.MessageDetails is not None:
            self.MessageDetails.export(outfile, level, namespace_, name_='MessageDetails', pretty_print=pretty_print)
    def exportLiteral(self, outfile, level, name_='MessageTransmissionDetailsType'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.MessageSenderDetails is not None:
            showIndent(outfile, level)
            outfile.write('MessageSenderDetails=model_.MessageSenderDetailsType(\n')
            self.MessageSenderDetails.exportLiteral(outfile, level, name_='MessageSenderDetails')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.MessageReceiverDetails is not None:
            showIndent(outfile, level)
            outfile.write('MessageReceiverDetails=model_.MessageReceiverDetailsType(\n')
            self.MessageReceiverDetails.exportLiteral(outfile, level, name_='MessageReceiverDetails')
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.MessageDetails is not None:
            showIndent(outfile, level)
            outfile.write('MessageDetails=model_.MessageDetailsType(\n')
            self.MessageDetails.exportLiteral(outfile, level, name_='MessageDetails')
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'MessageSenderDetails':
            obj_ = MessageSenderDetailsType.factory()
            obj_.build(child_)
            self.MessageSenderDetails = obj_
            obj_.original_tagname_ = 'MessageSenderDetails'
        elif nodeName_ == 'MessageReceiverDetails':
            obj_ = MessageReceiverDetailsType.factory()
            obj_.build(child_)
            self.MessageReceiverDetails = obj_
            obj_.original_tagname_ = 'MessageReceiverDetails'
        elif nodeName_ == 'MessageDetails':
            obj_ = MessageDetailsType.factory()
            obj_.build(child_)
            self.MessageDetails = obj_
            obj_.original_tagname_ = 'MessageDetails'
# end class MessageTransmissionDetailsType


class ErrorType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, Code=None, Text=None, Severity=None, Location=None):
        self.original_tagname_ = None
        self.Code = Code
        if Text is None:
            self.Text = []
        else:
            self.Text = Text
        self.Severity = Severity
        self.Location = Location
    def factory(*args_, **kwargs_):
        if ErrorType.subclass:
            return ErrorType.subclass(*args_, **kwargs_)
        else:
            return ErrorType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_Code(self): return self.Code
    def set_Code(self, Code): self.Code = Code
    def get_Text(self): return self.Text
    def set_Text(self, Text): self.Text = Text
    def add_Text(self, value): self.Text.append(value)
    def insert_Text_at(self, index, value): self.Text.insert(index, value)
    def replace_Text_at(self, index, value): self.Text[index] = value
    def get_Severity(self): return self.Severity
    def set_Severity(self, Severity): self.Severity = Severity
    def get_Location(self): return self.Location
    def set_Location(self, Location): self.Location = Location
    def validate_SeverityType(self, value):
        # Validate type SeverityType, a restriction on xs:NMTOKEN.
        pass
    def hasContent_(self):
        if (
            self.Code is not None or
            self.Text or
            self.Severity is not None or
            self.Location is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='ErrorType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='ErrorType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='ErrorType', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='ErrorType'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='ErrorType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.Code is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sCode>%s</%sCode>%s' % (namespace_, self.gds_format_string(quote_xml(self.Code).encode(ExternalEncoding), input_name='Code'), namespace_, eol_))
        for Text_ in self.Text:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sText>%s</%sText>%s' % (namespace_, self.gds_format_string(quote_xml(Text_).encode(ExternalEncoding), input_name='Text'), namespace_, eol_))
        if self.Severity is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sSeverity>%s</%sSeverity>%s' % (namespace_, self.gds_format_string(quote_xml(self.Severity).encode(ExternalEncoding), input_name='Severity'), namespace_, eol_))
        if self.Location is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sLocation>%s</%sLocation>%s' % (namespace_, self.gds_format_string(quote_xml(self.Location).encode(ExternalEncoding), input_name='Location'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='ErrorType'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.Code is not None:
            showIndent(outfile, level)
            outfile.write('Code=%s,\n' % quote_python(self.Code).encode(ExternalEncoding))
        showIndent(outfile, level)
        outfile.write('Text=[\n')
        level += 1
        for Text_ in self.Text:
            showIndent(outfile, level)
            outfile.write('%s,\n' % quote_python(Text_).encode(ExternalEncoding))
        level -= 1
        showIndent(outfile, level)
        outfile.write('],\n')
        if self.Severity is not None:
            showIndent(outfile, level)
            outfile.write('Severity=%s,\n' % quote_python(self.Severity).encode(ExternalEncoding))
        if self.Location is not None:
            showIndent(outfile, level)
            outfile.write('Location=%s,\n' % quote_python(self.Location).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'Code':
            Code_ = child_.text
            Code_ = self.gds_validate_string(Code_, node, 'Code')
            self.Code = Code_
        elif nodeName_ == 'Text':
            Text_ = child_.text
            Text_ = self.gds_validate_string(Text_, node, 'Text')
            self.Text.append(Text_)
        elif nodeName_ == 'Severity':
            Severity_ = child_.text
            Severity_ = self.gds_validate_string(Severity_, node, 'Severity')
            self.Severity = Severity_
            self.validate_SeverityType(self.Severity)    # validate type SeverityType
        elif nodeName_ == 'Location':
            Location_ = child_.text
            Location_ = self.gds_validate_string(Location_, node, 'Location')
            self.Location = Location_
# end class ErrorType


class To(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, PartyId=None, Role=None):
        self.original_tagname_ = None
        self.PartyId = PartyId
        self.Role = Role
    def factory(*args_, **kwargs_):
        if To.subclass:
            return To.subclass(*args_, **kwargs_)
        else:
            return To(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_PartyId(self): return self.PartyId
    def set_PartyId(self, PartyId): self.PartyId = PartyId
    def get_Role(self): return self.Role
    def set_Role(self, Role): self.Role = Role
    def hasContent_(self):
        if (
            self.PartyId is not None or
            self.Role is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='To', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='To')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='To', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='To'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='To', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.PartyId is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sPartyId>%s</%sPartyId>%s' % (namespace_, self.gds_format_string(quote_xml(self.PartyId).encode(ExternalEncoding), input_name='PartyId'), namespace_, eol_))
        if self.Role is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sRole>%s</%sRole>%s' % (namespace_, self.gds_format_string(quote_xml(self.Role).encode(ExternalEncoding), input_name='Role'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='To'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.PartyId is not None:
            showIndent(outfile, level)
            outfile.write('PartyId=%s,\n' % quote_python(self.PartyId).encode(ExternalEncoding))
        if self.Role is not None:
            showIndent(outfile, level)
            outfile.write('Role=%s,\n' % quote_python(self.Role).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'PartyId':
            PartyId_ = child_.text
            PartyId_ = self.gds_validate_string(PartyId_, node, 'PartyId')
            self.PartyId = PartyId_
        elif nodeName_ == 'Role':
            Role_ = child_.text
            Role_ = self.gds_validate_string(Role_, node, 'Role')
            self.Role = Role_
# end class To


class From(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, PartyId=None, Role=None):
        self.original_tagname_ = None
        self.PartyId = PartyId
        self.Role = Role
    def factory(*args_, **kwargs_):
        if From.subclass:
            return From.subclass(*args_, **kwargs_)
        else:
            return From(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_PartyId(self): return self.PartyId
    def set_PartyId(self, PartyId): self.PartyId = PartyId
    def get_Role(self): return self.Role
    def set_Role(self, Role): self.Role = Role
    def hasContent_(self):
        if (
            self.PartyId is not None or
            self.Role is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='From', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='From')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='From', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='From'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='From', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.PartyId is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sPartyId>%s</%sPartyId>%s' % (namespace_, self.gds_format_string(quote_xml(self.PartyId).encode(ExternalEncoding), input_name='PartyId'), namespace_, eol_))
        if self.Role is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sRole>%s</%sRole>%s' % (namespace_, self.gds_format_string(quote_xml(self.Role).encode(ExternalEncoding), input_name='Role'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='From'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.PartyId is not None:
            showIndent(outfile, level)
            outfile.write('PartyId=%s,\n' % quote_python(self.PartyId).encode(ExternalEncoding))
        if self.Role is not None:
            showIndent(outfile, level)
            outfile.write('Role=%s,\n' % quote_python(self.Role).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'PartyId':
            PartyId_ = child_.text
            PartyId_ = self.gds_validate_string(PartyId_, node, 'PartyId')
            self.PartyId = PartyId_
        elif nodeName_ == 'Role':
            Role_ = child_.text
            Role_ = self.gds_validate_string(Role_, node, 'Role')
            self.Role = Role_
# end class From


class AcknowledgementType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, From=None, To=None, MessageData=None, Reason=None):
        self.original_tagname_ = None
        if From is None:
            self.From = []
        else:
            self.From = From
        if To is None:
            self.To = []
        else:
            self.To = To
        self.MessageData = MessageData
        self.Reason = Reason
    def factory(*args_, **kwargs_):
        if AcknowledgementType.subclass:
            return AcknowledgementType.subclass(*args_, **kwargs_)
        else:
            return AcknowledgementType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_From(self): return self.From
    def set_From(self, From): self.From = From
    def add_From(self, value): self.From.append(value)
    def insert_From_at(self, index, value): self.From.insert(index, value)
    def replace_From_at(self, index, value): self.From[index] = value
    def get_To(self): return self.To
    def set_To(self, To): self.To = To
    def add_To(self, value): self.To.append(value)
    def insert_To_at(self, index, value): self.To.insert(index, value)
    def replace_To_at(self, index, value): self.To[index] = value
    def get_MessageData(self): return self.MessageData
    def set_MessageData(self, MessageData): self.MessageData = MessageData
    def get_Reason(self): return self.Reason
    def set_Reason(self, Reason): self.Reason = Reason
    def hasContent_(self):
        if (
            self.From or
            self.To or
            self.MessageData is not None or
            self.Reason is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='AcknowledgementType', namespacedef_=' xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" ', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='AcknowledgementType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='AcknowledgementType', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='AcknowledgementType'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='AcknowledgementType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        for From_ in self.From:
            From_.export(outfile, level, namespace_='eb:', name_='From', pretty_print=pretty_print)
        for To_ in self.To:
            To_.export(outfile, level, namespace_='eb:', name_='To', pretty_print=pretty_print)
        if self.MessageData is not None:
            self.MessageData.export(outfile, level, namespace_, name_='MessageData', pretty_print=pretty_print)
        if self.Reason is not None:
            self.Reason.export(outfile, level, namespace_, name_='Reason', pretty_print=pretty_print)
    def exportLiteral(self, outfile, level, name_='AcknowledgementType'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        showIndent(outfile, level)
        outfile.write('From=[\n')
        level += 1
        for From_ in self.From:
            showIndent(outfile, level)
            outfile.write('model_.From(\n')
            From_.exportLiteral(outfile, level)
            showIndent(outfile, level)
            outfile.write('),\n')
        level -= 1
        showIndent(outfile, level)
        outfile.write('],\n')
        showIndent(outfile, level)
        outfile.write('To=[\n')
        level += 1
        for To_ in self.To:
            showIndent(outfile, level)
            outfile.write('model_.To(\n')
            To_.exportLiteral(outfile, level)
            showIndent(outfile, level)
            outfile.write('),\n')
        level -= 1
        showIndent(outfile, level)
        outfile.write('],\n')
        if self.MessageData is not None:
            showIndent(outfile, level)
            outfile.write('MessageData=model_.MessageData(\n')
            self.MessageData.exportLiteral(outfile, level)
            showIndent(outfile, level)
            outfile.write('),\n')
        if self.Reason is not None:
            showIndent(outfile, level)
            outfile.write('Reason=model_.Reason(\n')
            self.Reason.exportLiteral(outfile, level)
            showIndent(outfile, level)
            outfile.write('),\n')
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'From':
            obj_ = From.factory()
            obj_.build(child_)
            self.From.append(obj_)
            obj_.original_tagname_ = 'From'
        elif nodeName_ == 'To':
            obj_ = To.factory()
            obj_.build(child_)
            self.To.append(obj_)
            obj_.original_tagname_ = 'To'
        elif nodeName_ == 'MessageData':
            obj_ = MessageData.factory()
            obj_.build(child_)
            self.MessageData = obj_
            obj_.original_tagname_ = 'MessageData'
        elif nodeName_ == 'Reason':
            obj_ = Reason.factory()
            obj_.build(child_)
            self.Reason = obj_
            obj_.original_tagname_ = 'Reason'
# end class AcknowledgementType


class MessageSenderDetailsType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, FromIdentifier=None, FromIntermediator=None):
        self.original_tagname_ = None
        self.FromIdentifier = FromIdentifier
        self.FromIntermediator = FromIntermediator
    def factory(*args_, **kwargs_):
        if MessageSenderDetailsType.subclass:
            return MessageSenderDetailsType.subclass(*args_, **kwargs_)
        else:
            return MessageSenderDetailsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_FromIdentifier(self): return self.FromIdentifier
    def set_FromIdentifier(self, FromIdentifier): self.FromIdentifier = FromIdentifier
    def get_FromIntermediator(self): return self.FromIntermediator
    def set_FromIntermediator(self, FromIntermediator): self.FromIntermediator = FromIntermediator
    def validate_genericStringType2_35(self, value):
        # Validate type genericStringType2_35, a restriction on xs:string.
        pass
    def hasContent_(self):
        if (
            self.FromIdentifier is not None or
            self.FromIntermediator is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='MessageSenderDetailsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='MessageSenderDetailsType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='MessageSenderDetailsType', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MessageSenderDetailsType'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='MessageSenderDetailsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.FromIdentifier is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sFromIdentifier>%s</%sFromIdentifier>%s' % (namespace_, self.gds_format_string(quote_xml(self.FromIdentifier).encode(ExternalEncoding), input_name='FromIdentifier'), namespace_, eol_))
        if self.FromIntermediator is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sFromIntermediator>%s</%sFromIntermediator>%s' % (namespace_, self.gds_format_string(quote_xml(self.FromIntermediator).encode(ExternalEncoding), input_name='FromIntermediator'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='MessageSenderDetailsType'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.FromIdentifier is not None:
            showIndent(outfile, level)
            outfile.write('FromIdentifier=%s,\n' % quote_python(self.FromIdentifier).encode(ExternalEncoding))
        if self.FromIntermediator is not None:
            showIndent(outfile, level)
            outfile.write('FromIntermediator=%s,\n' % quote_python(self.FromIntermediator).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'FromIdentifier':
            FromIdentifier_ = child_.text
            FromIdentifier_ = self.gds_validate_string(FromIdentifier_, node, 'FromIdentifier')
            self.FromIdentifier = FromIdentifier_
            self.validate_genericStringType2_35(self.FromIdentifier)    # validate type genericStringType2_35
        elif nodeName_ == 'FromIntermediator':
            FromIntermediator_ = child_.text
            FromIntermediator_ = self.gds_validate_string(FromIntermediator_, node, 'FromIntermediator')
            self.FromIntermediator = FromIntermediator_
            self.validate_genericStringType2_35(self.FromIntermediator)    # validate type genericStringType2_35
# end class MessageSenderDetailsType


class MessageReceiverDetailsType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, ToIdentifier=None, ToIntermediator=None):
        self.original_tagname_ = None
        self.ToIdentifier = ToIdentifier
        self.ToIntermediator = ToIntermediator
    def factory(*args_, **kwargs_):
        if MessageReceiverDetailsType.subclass:
            return MessageReceiverDetailsType.subclass(*args_, **kwargs_)
        else:
            return MessageReceiverDetailsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_ToIdentifier(self): return self.ToIdentifier
    def set_ToIdentifier(self, ToIdentifier): self.ToIdentifier = ToIdentifier
    def get_ToIntermediator(self): return self.ToIntermediator
    def set_ToIntermediator(self, ToIntermediator): self.ToIntermediator = ToIntermediator
    def validate_genericStringType2_35(self, value):
        # Validate type genericStringType2_35, a restriction on xs:string.
        pass
    def hasContent_(self):
        if (
            self.ToIdentifier is not None or
            self.ToIntermediator is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='MessageReceiverDetailsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='MessageReceiverDetailsType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='MessageReceiverDetailsType', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MessageReceiverDetailsType'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='MessageReceiverDetailsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.ToIdentifier is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sToIdentifier>%s</%sToIdentifier>%s' % (namespace_, self.gds_format_string(quote_xml(self.ToIdentifier).encode(ExternalEncoding), input_name='ToIdentifier'), namespace_, eol_))
        if self.ToIntermediator is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sToIntermediator>%s</%sToIntermediator>%s' % (namespace_, self.gds_format_string(quote_xml(self.ToIntermediator).encode(ExternalEncoding), input_name='ToIntermediator'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='MessageReceiverDetailsType'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.ToIdentifier is not None:
            showIndent(outfile, level)
            outfile.write('ToIdentifier=%s,\n' % quote_python(self.ToIdentifier).encode(ExternalEncoding))
        if self.ToIntermediator is not None:
            showIndent(outfile, level)
            outfile.write('ToIntermediator=%s,\n' % quote_python(self.ToIntermediator).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'ToIdentifier':
            ToIdentifier_ = child_.text
            ToIdentifier_ = self.gds_validate_string(ToIdentifier_, node, 'ToIdentifier')
            self.ToIdentifier = ToIdentifier_
            self.validate_genericStringType2_35(self.ToIdentifier)    # validate type genericStringType2_35
        elif nodeName_ == 'ToIntermediator':
            ToIntermediator_ = child_.text
            ToIntermediator_ = self.gds_validate_string(ToIntermediator_, node, 'ToIntermediator')
            self.ToIntermediator = ToIntermediator_
            self.validate_genericStringType2_35(self.ToIntermediator)    # validate type genericStringType2_35
# end class MessageReceiverDetailsType


class MessageDetailsType(GeneratedsSuper):
    subclass = None
    superclass = None
    def __init__(self, MessageIdentifier=None, MessageTimeStamp=None, RefToMessageIdentifier=None):
        self.original_tagname_ = None
        self.MessageIdentifier = MessageIdentifier
        self.MessageTimeStamp = MessageTimeStamp
        self.RefToMessageIdentifier = RefToMessageIdentifier
    def factory(*args_, **kwargs_):
        if MessageDetailsType.subclass:
            return MessageDetailsType.subclass(*args_, **kwargs_)
        else:
            return MessageDetailsType(*args_, **kwargs_)
    factory = staticmethod(factory)
    def get_MessageIdentifier(self): return self.MessageIdentifier
    def set_MessageIdentifier(self, MessageIdentifier): self.MessageIdentifier = MessageIdentifier
    def get_MessageTimeStamp(self): return self.MessageTimeStamp
    def set_MessageTimeStamp(self, MessageTimeStamp): self.MessageTimeStamp = MessageTimeStamp
    def get_RefToMessageIdentifier(self): return self.RefToMessageIdentifier
    def set_RefToMessageIdentifier(self, RefToMessageIdentifier): self.RefToMessageIdentifier = RefToMessageIdentifier
    def validate_genericStringType6_98(self, value):
        # Validate type genericStringType6_98, a restriction on xs:string.
        pass
    def validate_genericStringType2_35(self, value):
        # Validate type genericStringType2_35, a restriction on xs:string.
        pass
    def hasContent_(self):
        if (
            self.MessageIdentifier is not None or
            self.MessageTimeStamp is not None or
            self.RefToMessageIdentifier is not None
        ):
            return True
        else:
            return False
    def export(self, outfile, level, namespace_='', name_='MessageDetailsType', namespacedef_='', pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.original_tagname_ is not None:
            name_ = self.original_tagname_
        showIndent(outfile, level, pretty_print)
        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
        already_processed = set()
        self.exportAttributes(outfile, level, already_processed, namespace_, name_='MessageDetailsType')
        if self.hasContent_():
            outfile.write('>%s' % (eol_, ))
            self.exportChildren(outfile, level + 1, namespace_='', name_='MessageDetailsType', pretty_print=pretty_print)
            showIndent(outfile, level, pretty_print)
            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
        else:
            outfile.write('/>%s' % (eol_, ))
    def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MessageDetailsType'):
        pass
    def exportChildren(self, outfile, level, namespace_='', name_='MessageDetailsType', fromsubclass_=False, pretty_print=True):
        if pretty_print:
            eol_ = '\n'
        else:
            eol_ = ''
        if self.MessageIdentifier is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sMessageIdentifier>%s</%sMessageIdentifier>%s' % (namespace_, self.gds_format_string(quote_xml(self.MessageIdentifier).encode(ExternalEncoding), input_name='MessageIdentifier'), namespace_, eol_))
        if self.MessageTimeStamp is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sMessageTimeStamp>%s</%sMessageTimeStamp>%s' % (namespace_, self.gds_format_string(quote_xml(self.MessageTimeStamp).encode(ExternalEncoding), input_name='MessageTimeStamp'), namespace_, eol_))
        if self.RefToMessageIdentifier is not None:
            showIndent(outfile, level, pretty_print)
            outfile.write('<%sRefToMessageIdentifier>%s</%sRefToMessageIdentifier>%s' % (namespace_, self.gds_format_string(quote_xml(self.RefToMessageIdentifier).encode(ExternalEncoding), input_name='RefToMessageIdentifier'), namespace_, eol_))
    def exportLiteral(self, outfile, level, name_='MessageDetailsType'):
        level += 1
        already_processed = set()
        self.exportLiteralAttributes(outfile, level, already_processed, name_)
        if self.hasContent_():
            self.exportLiteralChildren(outfile, level, name_)
    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
        pass
    def exportLiteralChildren(self, outfile, level, name_):
        if self.MessageIdentifier is not None:
            showIndent(outfile, level)
            outfile.write('MessageIdentifier=%s,\n' % quote_python(self.MessageIdentifier).encode(ExternalEncoding))
        if self.MessageTimeStamp is not None:
            showIndent(outfile, level)
            outfile.write('MessageTimeStamp=%s,\n' % quote_python(self.MessageTimeStamp).encode(ExternalEncoding))
        if self.RefToMessageIdentifier is not None:
            showIndent(outfile, level)
            outfile.write('RefToMessageIdentifier=%s,\n' % quote_python(self.RefToMessageIdentifier).encode(ExternalEncoding))
    def build(self, node):
        already_processed = set()
        self.buildAttributes(node, node.attrib, already_processed)
        for child in node:
            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
            self.buildChildren(child, node, nodeName_)
        return self
    def buildAttributes(self, node, attrs, already_processed):
        pass
    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
        if nodeName_ == 'MessageIdentifier':
            MessageIdentifier_ = child_.text
            MessageIdentifier_ = self.gds_validate_string(MessageIdentifier_, node, 'MessageIdentifier')
            self.MessageIdentifier = MessageIdentifier_
            self.validate_genericStringType6_98(self.MessageIdentifier)    # validate type genericStringType6_98
        elif nodeName_ == 'MessageTimeStamp':
            MessageTimeStamp_ = child_.text
            MessageTimeStamp_ = self.gds_validate_string(MessageTimeStamp_, node, 'MessageTimeStamp')
            self.MessageTimeStamp = MessageTimeStamp_
            self.validate_genericStringType2_35(self.MessageTimeStamp)    # validate type genericStringType2_35
        elif nodeName_ == 'RefToMessageIdentifier':
            RefToMessageIdentifier_ = child_.text
            RefToMessageIdentifier_ = self.gds_validate_string(RefToMessageIdentifier_, node, 'RefToMessageIdentifier')
            self.RefToMessageIdentifier = RefToMessageIdentifier_
            self.validate_genericStringType6_98(self.RefToMessageIdentifier)    # validate type genericStringType6_98
# end class MessageDetailsType


GDSClassesMapping = {
    'Acknowledgement': AcknowledgementType,
    'MessageDetails': MessageDetailsType,
    'MessageReceiverDetails': MessageReceiverDetailsType,
    'MessageTransmissionDetails': MessageTransmissionDetailsType,
    'Error': ErrorType,
    'MessageSenderDetails': MessageSenderDetailsType,
}


USAGE_TEXT = """
Usage: python <Parser>.py [ -s ] <in_xml_file>
"""


def usage():
    print USAGE_TEXT
    sys.exit(1)


def get_root_tag(node):
    tag = Tag_pattern_.match(node.tag).groups()[-1]
    rootClass = GDSClassesMapping.get(tag)
    if rootClass is None:
        rootClass = globals().get(tag)
    return tag, rootClass


def parse(inFileName, silence=False):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'Finvoiceack'
        rootClass = Finvoiceack
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    if not silence:
        sys.stdout.write('<?xml version="1.0" ?>\n')
        rootObj.export(
            sys.stdout, 0, name_=rootTag,
            namespacedef_='',
            pretty_print=True)
    return rootObj


def parseEtree(inFileName, silence=False):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'Finvoiceack'
        rootClass = Finvoiceack
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    mapping = {}
    rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping)
    reverse_mapping = rootObj.gds_reverse_node_mapping(mapping)
    if not silence:
        content = etree_.tostring(
            rootElement, pretty_print=True,
            xml_declaration=True, encoding="utf-8")
        sys.stdout.write(content)
        sys.stdout.write('\n')
    return rootObj, rootElement, mapping, reverse_mapping


def parseString(inString, silence=False):
    from StringIO import StringIO
    doc = parsexml_(StringIO(inString))
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'Finvoiceack'
        rootClass = Finvoiceack
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    if not silence:
        sys.stdout.write('<?xml version="1.0" ?>\n')
        rootObj.export(
            sys.stdout, 0, name_=rootTag,
            namespacedef_='')
    return rootObj


def parseLiteral(inFileName, silence=False):
    doc = parsexml_(inFileName)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'Finvoiceack'
        rootClass = Finvoiceack
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    if not silence:
        sys.stdout.write('#from ack import *\n\n')
        sys.stdout.write('import ack as model_\n\n')
        sys.stdout.write('rootObj = model_.rootClass(\n')
        rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
        sys.stdout.write(')\n')
    return rootObj


def main():
    args = sys.argv[1:]
    if len(args) == 1:
        parse(args[0])
    else:
        usage()


if __name__ == '__main__':
    #import pdb; pdb.set_trace()
    main()


__all__ = [
    "AcknowledgementType",
    "ErrorType",
    "Finvoiceack",
    "From",
    "MessageData",
    "MessageDetailsType",
    "MessageReceiverDetailsType",
    "MessageSenderDetailsType",
    "MessageTransmissionDetailsType",
    "Reason",
    "To"
]
