diff --git a/README b/README
index f3dd65e58bc5e39ee4ab292536ac9df6d65d6beb..0cbb735b7cb2b672355a09c9b98fa84656f8f00f 100644
--- a/README
+++ b/README
@@ -141,6 +141,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 Change history
 --------------
 
+Version 2.19b (02/16/2016)
+
+- Modified generated code so that it will run under both Python 2
+  and Python 3.  There is no longer any need to generate different
+  code for Python 2 and Python 3.  If fact, the "--py3" command line
+  option has been removed.
+
 Version 2.19a (02/08/2016)
 
 - Added the ability to generate code that can run under Python 3.
diff --git a/generateDS.html b/generateDS.html
index b85250c52ecb59be1878dd5dc8b9c4bd0f41957e..f956893205de696807d554b1d364f0d7fc09593b 100644
--- a/generateDS.html
+++ b/generateDS.html
@@ -229,7 +229,7 @@ They are used by updateversion.py. -->
 <col class="field-name" />
 <col class="field-body" />
 <tbody valign="top">
-<tr class="field"><th class="field-name">date:</th><td class="field-body">February 06, 2016</td>
+<tr class="field"><th class="field-name">date:</th><td class="field-body">February 15, 2016</td>
 </tr>
 </tbody>
 </table>
@@ -437,6 +437,9 @@ process the contents of the XML file. The user can also generate
 and extend multiple subclass files which use a single, common
 superclass file, thus implementing a number of different processes
 on the same XML document type.</p>
+<p><tt class="docutils literal">generateDS.py</tt> can be run under either Python 2 or Python 3.  The
+generated Python code (both superclass and subclass modules) can be
+run under either Python 2 or Python 3.</p>
 <p>This document explains (1) how to use <tt class="docutils literal">generateDS.py</tt>; (2) how
 to use the Python code and data structures that it generates; and
 (3) how to modify the generated code for special purposes.</p>
@@ -634,7 +637,6 @@ Options:
                              distribution.
     --fix-type-names=&quot;oldname1:newname1;oldname2:newname2;...&quot;
                              Fix up (replace) complex type names.
-    --py3                    Generate code for Python 3.
     --version                Print version and exit.
 
 Usage example:
@@ -915,13 +917,6 @@ $ generateDS.py --fix-type-names=&quot;type1:type1Aux&quot;
 $ generateDS.py --fix-type-names=&quot;type1;type2:type2Repl&quot;
 </pre>
 </dd>
-<dt>py3</dt>
-<dd>Generate code for Python 3; the default is to generate code for
-Python 2.  Generate code that will run under (and will have the
-same behavior under) Python 3.  You can, later, determine
-whether a file was generated for Python 2 or Python 3 by looking
-at the comments containing command line options near the top of
-the file.</dd>
 <dt>version</dt>
 <dd>Print out the current version of <tt class="docutils literal">generateDS.py</tt> and
 immediately exit.</dd>
@@ -3176,7 +3171,7 @@ following among others:</p>
 <div class="footer">
 <hr class="footer" />
 <a class="reference external" href="generateDS.txt">View document source</a>.
-Generated on: 2016-02-07 01:15 UTC.
+Generated on: 2016-02-15 23:30 UTC.
 Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
 
 </div>
diff --git a/generateDS.py b/generateDS.py
index 1237b5be11978cf70ded30339997a2aab06a7eb3..2fe477f558071f2767de4a0d8073c015374dae33 100755
--- a/generateDS.py
+++ b/generateDS.py
@@ -107,7 +107,6 @@ Options:
                              distribution.
     --fix-type-names="oldname1:newname1;oldname2:newname2;..."
                              Fix up (replace) complex type names.
-    --py3                    Generate code for Python 3.
     --version                Print version and exit.
 
 Usage example:
@@ -206,6 +205,11 @@ logging.disable(logging.INFO)
 VERSION = '2.19a'
 ##VERSION##
 
+if sys.version_info.major == 2:
+    BaseStrType = basestring
+else:
+    BaseStrType = str
+
 GenerateProperties = 0
 UseGetterSetter = 'new'
 UseOldSimpleTypeValidators = False
@@ -270,7 +274,6 @@ SingleFileOutput = True
 OutputDirectory = None
 ModuleSuffix = ""
 PreserveCdataTags = False
-GeneratePy3 = False
 
 SchemaToPythonTypeMap = {}
 
@@ -1964,24 +1967,25 @@ def generateExportFn_1(wrt, child, name, namespace, fill):
                 fill, mappedName, default, ))
         wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         # fixlist
-        encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
         if (child.getSimpleType() in SimpleTypeDict and
                 SimpleTypeDict[child.getSimpleType()].isListType()):
             s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% " \
-                "(namespace_, self.gds_format_string(quote_xml" \
-                "(' '.join(self.%s))%s, " \
-                "input_name='%s'), namespace_, eol_))\n" % \
-                (fill, name, name, mappedName, encoding, name, )
+                "(namespace_, self.gds_encode(self.gds_format_string(" \
+                "quote_xml" \
+                "(' '.join(self.%s)), " \
+                "input_name='%s')), namespace_, eol_))\n" % \
+                (fill, name, name, mappedName, name, )
         else:
             namespace = 'namespace_'
             if child.prefix and 'ref' in child.attrs:
                 namespace = "'%s:'" % child.prefix
             s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% " \
-                "(%s, self.gds_format_string(quote_xml(self.%s)%s, " \
-                "input_name='%s'), " \
+                "(%s, self.gds_encode(self.gds_format_string(" \
+                "quote_xml(self.%s), " \
+                "input_name='%s')), " \
                 "%s, eol_))\n" % \
                 (fill, name, name, namespace, mappedName,
-                    encoding, name, namespace, )
+                    name, namespace, )
         wrt(s1)
     elif (child_type in IntegerType or
             child_type == PositiveIntegerType or
@@ -2127,11 +2131,11 @@ def generateExportFn_2(wrt, child, name, namespace, fill):
             child_type == TokenType or
             child_type in DateTimeGroupType):
         wrt('%s        showIndent(outfile, level, pretty_print)\n' % fill)
-        encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
         wrt("%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% "
-            "(namespace_, self.gds_format_string(quote_xml(%s_)"
-            "%s, input_name='%s'), namespace_, eol_))\n" %
-            (fill, name, name, cleanName, encoding, name,))
+            "(namespace_, self.gds_encode(self.gds_format_string("
+            "quote_xml(%s_), "
+            "input_name='%s')), namespace_, eol_))\n" %
+            (fill, name, name, cleanName, name,))
     elif (child_type in IntegerType or
             child_type == PositiveIntegerType or
             child_type == NonPositiveIntegerType or
@@ -2269,20 +2273,19 @@ def generateExportFn_3(wrt, child, name, namespace, fill):
                 fill, mappedName, default, ))
         wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         # fixlist
-        encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
         if (child.getSimpleType() in SimpleTypeDict and
                 SimpleTypeDict[child.getSimpleType()].isListType()):
             s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% " \
-                "(namespace_, self.gds_format_string(" \
-                "quote_xml(' '.join(self.%s))%s, " \
-                "input_name='%s'), namespace_, eol_))\n" % \
-                (fill, name, name, mappedName, encoding, name, )
+                "(namespace_, self.gds_encode(self.gds_format_string(" \
+                "quote_xml(' '.join(self.%s)), " \
+                "input_name='%s')), namespace_, eol_))\n" % \
+                (fill, name, name, mappedName, name, )
         else:
             s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% " \
-                "(namespace_, self.gds_format_string(" \
-                "quote_xml(self.%s)%s, " \
-                "input_name='%s'), namespace_, eol_))\n" % \
-                (fill, name, name, mappedName, encoding, name, )
+                "(namespace_, self.gds_encode(self.gds_format_string(" \
+                "quote_xml(self.%s), " \
+                "input_name='%s')), namespace_, eol_))\n" % \
+                (fill, name, name, mappedName, name, )
         wrt(s1)
     elif (child_type in IntegerType or
             child_type == PositiveIntegerType or
@@ -2648,12 +2651,11 @@ def generateExportAttributes(wrt, element, hasAttributes):
                     attrDefType in IDTypes or
                     attrDefType == TokenType or
                     attrDefType in DateTimeGroupType):
-                encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
                 s1 = '''%s        outfile.write(' %s=%%s' %% ''' \
-                    '''(self.gds_format_string(quote_attrib(''' \
-                    '''self.%s)%s, ''' \
-                    '''input_name='%s'), ))\n''' % \
-                    (indent, orig_name, cleanName, encoding, name, )
+                    '''(self.gds_encode(self.gds_format_string(quote_attrib(''' \
+                    '''self.%s), ''' \
+                    '''input_name='%s')), ))\n''' % \
+                    (indent, orig_name, cleanName, name, )
             elif (attrDefType in IntegerType or
                     attrDefType == PositiveIntegerType or
                     attrDefType == NonPositiveIntegerType or
@@ -2820,11 +2822,10 @@ def generateExportFn(wrt, prefix, element, namespace, nameSpacesDef):
         if element.getSimpleContent():
             wrt("            outfile.write('>')\n")
             if not element.isMixed():
-                encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
                 wrt("            outfile.write((quote_xml(self.valueOf_) "
                     "if type(self.valueOf_) is str else "
-                    "str(self.valueOf_))%s)\n" % (
-                        encoding, ))
+                    "self.gds_encode(str(self.valueOf_))))\n"
+                    )
         else:
             wrt("            outfile.write('>%s' % (eol_, ))\n")
         wrt("            self.exportChildren(outfile, level + 1, "
@@ -2945,21 +2946,20 @@ def generateExportLiteralFn_1(wrt, child, name, fill):
                 childType == TokenType or
                 childType in DateTimeGroupType):
             wrt('%s            showIndent(outfile, level)\n' % fill)
-            encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
             if (child.getSimpleType() in SimpleTypeDict and
                     SimpleTypeDict[child.getSimpleType()].isListType()):
                 wrt("%s            if self.%s:\n" % (fill, mappedName, ))
                 wrt("%s                outfile.write('%s=%%s,\\n' %% "
-                    "quote_python(' '.join(self.%s))"
-                    "%s) \n" %
+                    "self.gds_encode(quote_python(' '.join(self.%s)))"
+                    ") \n" %
                     (fill, mappedName, mappedName, encoding, ))
                 wrt("%s            else:\n" % (fill, ))
                 wrt("%s                outfile.write('%s=None,\\n')\n" %
                     (fill, mappedName, ))
             else:
                 wrt("%s            outfile.write('%s=%%s,\\n' %% "
-                    "quote_python(self.%s)%s)\n" %
-                    (fill, mappedName, mappedName, encoding, ))
+                    "self.gds_encode(quote_python(self.%s)))\n" %
+                    (fill, mappedName, mappedName, ))
         elif (childType in IntegerType or
                 childType == PositiveIntegerType or
                 childType == NonPositiveIntegerType or
@@ -3020,10 +3020,9 @@ def generateExportLiteralFn_2(wrt, child, name, fill):
     elif (childType in StringType or
             childType == TokenType or
             childType in DateTimeGroupType):
-        encoding = '' if GeneratePy3 else '.encode(ExternalEncoding)'
         wrt('%s        showIndent(outfile, level)\n' % fill)
-        wrt("%s        outfile.write('%%s,\\n' %% quote_python(%s_)"
-            "%s)\n" % (fill, name, encoding, ))
+        wrt("%s        outfile.write('%%s,\\n' %% self.gds_encode("
+            "quote_python(%s_)))\n" % (fill, name, ))
     elif (childType in IntegerType or
             childType == PositiveIntegerType or
             childType == NonPositiveIntegerType or
@@ -4105,30 +4104,21 @@ def generateCtor(wrt, prefix, element):
             mbrname = name
         attrType = attrDef.getType()
         if attrType == DateTimeType:
-            if GeneratePy3:
-                wrt("        if isinstance(%s, str):\n" % (mbrname, ))
-            else:
-                wrt("        if isinstance(%s, basestring):\n" % (mbrname, ))
+            wrt("        if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
             wrt("            initvalue_ = datetime_.datetime.strptime("
                 "%s, '%%Y-%%m-%%dT%%H:%%M:%%S')\n" % (mbrname, ))
             wrt("        else:\n")
             wrt("            initvalue_ = %s\n" % (mbrname, ))
             wrt("        self.%s = initvalue_\n" % (name, ))
         elif attrType == DateType:
-            if GeneratePy3:
-                wrt("        if isinstance(%s, str):\n" % (mbrname, ))
-            else:
-                wrt("        if isinstance(%s, basestring):\n" % (mbrname, ))
+            wrt("        if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
             wrt("            initvalue_ = datetime_.datetime.strptime("
                 "%s, '%%Y-%%m-%%d').date()\n" % (mbrname, ))
             wrt("        else:\n")
             wrt("            initvalue_ = %s\n" % (mbrname, ))
             wrt("        self.%s = initvalue_\n" % (name, ))
         elif attrType == TimeType:
-            if GeneratePy3:
-                wrt("        if isinstance(%s, str):\n" % (mbrname, ))
-            else:
-                wrt("        if isinstance(%s, basestring):\n" % (mbrname, ))
+            wrt("        if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
             wrt("            initvalue_ = datetime_.datetime.strptime("
                 "%s, '%%H:%%M:%%S').time()\n" % (mbrname, ))
             wrt("        else:\n")
@@ -4157,10 +4147,7 @@ def generateCtor(wrt, prefix, element):
             else:
                 wrt('        self.anytypeobjs_ = anytypeobjs_\n')
         elif childType == DateTimeType and child.getMaxOccurs() <= 1:
-            if GeneratePy3:
-                wrt("        if isinstance(%s, str):\n" % (mbrname, ))
-            else:
-                wrt("        if isinstance(%s, basestring):\n" % (mbrname, ))
+            wrt("        if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
             wrt("            initvalue_ = datetime_.datetime.strptime("
                 "%s, '%%Y-%%m-%%dT%%H:%%M:%%S')\n" % (mbrname, ))
             wrt("        else:\n")
@@ -4170,10 +4157,7 @@ def generateCtor(wrt, prefix, element):
             else:
                 wrt("        self.%s = initvalue_\n" % (name, ))
         elif childType == DateType and child.getMaxOccurs() <= 1:
-            if GeneratePy3:
-                wrt("        if isinstance(%s, str):\n" % (mbrname, ))
-            else:
-                wrt("        if isinstance(%s, basestring):\n" % (mbrname, ))
+            wrt("        if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
             wrt("            initvalue_ = datetime_.datetime.strptime("
                 "%s, '%%Y-%%m-%%d').date()\n" % (mbrname, ))
             wrt("        else:\n")
@@ -4183,10 +4167,7 @@ def generateCtor(wrt, prefix, element):
             else:
                 wrt("        self.%s = initvalue_\n" % (name, ))
         elif childType == TimeType and child.getMaxOccurs() <= 1:
-            if GeneratePy3:
-                wrt("        if isinstance(%s, str):\n" % (mbrname, ))
-            else:
-                wrt("        if isinstance(%s, basestring):\n" % (mbrname, ))
+            wrt("        if isinstance(%s, BaseStrType_):\n" % (mbrname, ))
             wrt("            initvalue_ = datetime_.datetime.strptime("
                 "%s, '%%H:%%M:%%S').time()\n" % (mbrname, ))
             wrt("        else:\n")
@@ -4936,6 +4917,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -5255,6 +5240,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             {gds_reverse_node_mapping_text}
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -5600,20 +5591,12 @@ def generateHeader(wrt, prefix, options, args, externalImports):
     else:
         preserve_cdata_tags_pat = ""
         preserve_cdata_get_text = Preserve_cdata_get_all_text2
-    if GeneratePy3:
-        gds_reverse_node_mapping_text = \
-            "return dict(((v, k) for k, v in mapping.items()))"
-        quote_xml_text = \
-            "s1 = (isinstance(inStr, str) and inStr or '%s' % inStr)"
-        quote_attrib_text = \
-            "s1 = (isinstance(inStr, str) and inStr or '%s' % inStr)"
-    else:
-        gds_reverse_node_mapping_text = \
-            "return dict(((v, k) for k, v in mapping.iteritems()))"
-        quote_xml_text = \
-            "s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)"
-        quote_attrib_text = \
-            "s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)"
+    gds_reverse_node_mapping_text = \
+        "return dict(((v, k) for k, v in mapping.iteritems()))"
+    quote_xml_text = \
+        "s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)"
+    quote_attrib_text = \
+        "s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)"
     s1 = TEMPLATE_HEADER.format(
         tstamp=tstamp,
         version=version,
@@ -6808,7 +6791,7 @@ def main():
         ExportWrite, ExportEtree, ExportLiteral, \
         FixTypeNames, SingleFileOutput, OutputDirectory, \
         ModuleSuffix, UseOldSimpleTypeValidators, \
-        PreserveCdataTags, CleanupNameList, GeneratePy3
+        PreserveCdataTags, CleanupNameList
     outputText = True
     args = sys.argv[1:]
     try:
@@ -6826,7 +6809,6 @@ def main():
                 'one-file-per-xsd', 'output-directory=',
                 'module-suffix=', 'use-old-simpletype-validators',
                 'preserve-cdata-tags', 'cleanup-name-list=',
-                'py3',
             ])
     except getopt.GetoptError:
         usage()
@@ -7003,8 +6985,8 @@ def main():
                 if sys.version_info.major == 2:
                     if (type(cleanup_pair) not in (list, tuple) or
                             len(cleanup_pair) != 2 or
-                            not isinstance(cleanup_pair[0], basestring) or
-                            not isinstance(cleanup_pair[1], basestring)):
+                            not isinstance(cleanup_pair[0], BaseStrType) or
+                            not isinstance(cleanup_pair[1], BaseStrType)):
                         raise RuntimeError(
                             'Option --cleanup-name-list contains '
                             'invalid element.')
@@ -7024,8 +7006,6 @@ def main():
                         'Option --cleanup-name-list contains invalid '
                         'pattern "%s".'
                         % cleanup_pair[0])
-        elif option[0] == '--py3':
-            GeneratePy3 = True
 
     if showVersion:
         print('generateDS.py version %s' % VERSION)
diff --git a/generateDS.txt b/generateDS.txt
index bba23bb87ccb3038b5e96313c934dd7af73e057a..9845a819aa1a0ce9b838b0fe6f24f1f2bb93af15 100644
--- a/generateDS.txt
+++ b/generateDS.txt
@@ -100,6 +100,10 @@ and extend multiple subclass files which use a single, common
 superclass file, thus implementing a number of different processes
 on the same XML document type.
 
+``generateDS.py`` can be run under either Python 2 or Python 3.  The
+generated Python code (both superclass and subclass modules) can be
+run under either Python 2 or Python 3.
+
 This document explains (1) how to use ``generateDS.py``; (2) how
 to use the Python code and data structures that it generates; and
 (3) how to modify the generated code for special purposes.
@@ -325,7 +329,6 @@ Here is the usage message displayed by ``generateDS.py``::
                                  distribution.
         --fix-type-names="oldname1:newname1;oldname2:newname2;..."
                                  Fix up (replace) complex type names.
-        --py3                    Generate code for Python 3.
         --version                Print version and exit.
 
     Usage example:
@@ -633,14 +636,6 @@ fix-type-names="oldname1:newname1;oldname2:newname2;..." Fix up
         $ generateDS.py --fix-type-names="type1:type1Aux"
         $ generateDS.py --fix-type-names="type1;type2:type2Repl"
 
-py3
-    Generate code for Python 3.  Generate code that will run under
-    (and will have the same behavior under) Python 3 (instead of
-    Python 2).  You can, later, determine whether a file was
-    generated for Python 2 or Python 3 by looking at the comments
-    containing command line options near the top of the file.  The
-    default is to generate code for Python 2.  
-
 version
     Print out the current version of ``generateDS.py`` and
     immediately exit.
diff --git a/librarytemplate_howto.html b/librarytemplate_howto.html
index 7b714698a56c0468627f87c796f81f7090bf6edf..ce787964ef90433b862d1b0eb70a4b68d8cf0b58 100644
--- a/librarytemplate_howto.html
+++ b/librarytemplate_howto.html
@@ -217,7 +217,7 @@ dkuhlman (at) davekuhlman (dot) org
 <col class="field-name" />
 <col class="field-body" />
 <tbody valign="top">
-<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.18a</td>
+<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.19a</td>
 </tr>
 </tbody>
 </table>
@@ -226,7 +226,7 @@ dkuhlman (at) davekuhlman (dot) org
 <col class="field-name" />
 <col class="field-body" />
 <tbody valign="top">
-<tr class="field"><th class="field-name">date:</th><td class="field-body">December 16, 2015</td>
+<tr class="field"><th class="field-name">date:</th><td class="field-body">February 08, 2016</td>
 </tr>
 </tbody>
 </table>
@@ -380,7 +380,7 @@ this command for your needs.  For example, you may need to use
 <div class="footer">
 <hr class="footer" />
 <a class="reference external" href="librarytemplate_howto.txt">View document source</a>.
-Generated on: 2015-12-16 20:55 UTC.
+Generated on: 2016-02-08 18:02 UTC.
 Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
 
 </div>
diff --git a/tests/OnePer/oneperType00_1One.py b/tests/OnePer/oneperType00_1One.py
index d504860cd2685f4e9ab97ea283cf99558ef1ed27..3a361bbe2efa38074d4dc3970a0a9d1ab65e8ceb 100644
--- a/tests/OnePer/oneperType00_1One.py
+++ b/tests/OnePer/oneperType00_1One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
diff --git a/tests/OnePer/oneperType00_2One.py b/tests/OnePer/oneperType00_2One.py
index d504860cd2685f4e9ab97ea283cf99558ef1ed27..3a361bbe2efa38074d4dc3970a0a9d1ab65e8ceb 100644
--- a/tests/OnePer/oneperType00_2One.py
+++ b/tests/OnePer/oneperType00_2One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
diff --git a/tests/OnePer/oneperType01_1One.py b/tests/OnePer/oneperType01_1One.py
index 93f9e63a040fe36ead065a886a0f7974351a311b..73c443de3190949c7b4f223641304b29e9ec0803 100644
--- a/tests/OnePer/oneperType01_1One.py
+++ b/tests/OnePer/oneperType01_1One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class oneperType01_1(GeneratedsSuper):
             eol_ = ''
         if self.username is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%susername>%s</%susername>%s' % (namespace_, self.gds_format_string(quote_xml(self.username).encode(ExternalEncoding), input_name='username'), namespace_, eol_))
+            outfile.write('<%susername>%s</%susername>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.username), input_name='username')), namespace_, eol_))
         if self.inner01 is not None:
             self.inner01.export(outfile, level, namespace_, name_='inner01', pretty_print=pretty_print)
     def build(self, node):
@@ -776,7 +786,7 @@ class oneperType01_2(GeneratedsSuper):
             eol_ = ''
         if self.userdescription is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%suserdescription>%s</%suserdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.userdescription).encode(ExternalEncoding), input_name='userdescription'), namespace_, eol_))
+            outfile.write('<%suserdescription>%s</%suserdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.userdescription), input_name='userdescription')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/OnePer/oneperType01_2One.py b/tests/OnePer/oneperType01_2One.py
index 93f9e63a040fe36ead065a886a0f7974351a311b..73c443de3190949c7b4f223641304b29e9ec0803 100644
--- a/tests/OnePer/oneperType01_2One.py
+++ b/tests/OnePer/oneperType01_2One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class oneperType01_1(GeneratedsSuper):
             eol_ = ''
         if self.username is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%susername>%s</%susername>%s' % (namespace_, self.gds_format_string(quote_xml(self.username).encode(ExternalEncoding), input_name='username'), namespace_, eol_))
+            outfile.write('<%susername>%s</%susername>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.username), input_name='username')), namespace_, eol_))
         if self.inner01 is not None:
             self.inner01.export(outfile, level, namespace_, name_='inner01', pretty_print=pretty_print)
     def build(self, node):
@@ -776,7 +786,7 @@ class oneperType01_2(GeneratedsSuper):
             eol_ = ''
         if self.userdescription is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%suserdescription>%s</%suserdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.userdescription).encode(ExternalEncoding), input_name='userdescription'), namespace_, eol_))
+            outfile.write('<%suserdescription>%s</%suserdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.userdescription), input_name='userdescription')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/OnePer/oneperType02_1One.py b/tests/OnePer/oneperType02_1One.py
index d477ecea9763303bc135f9b9650e8de4ebec7876..339dabeb4899224541cf1af0be07661fe3c301ab 100644
--- a/tests/OnePer/oneperType02_1One.py
+++ b/tests/OnePer/oneperType02_1One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class oneperType02_1(GeneratedsSuper):
             eol_ = ''
         if self.clientname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sclientname>%s</%sclientname>%s' % (namespace_, self.gds_format_string(quote_xml(self.clientname).encode(ExternalEncoding), input_name='clientname'), namespace_, eol_))
+            outfile.write('<%sclientname>%s</%sclientname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.clientname), input_name='clientname')), namespace_, eol_))
         if self.inner01 is not None:
             self.inner01.export(outfile, level, namespace_, name_='inner01', pretty_print=pretty_print)
     def build(self, node):
@@ -776,7 +786,7 @@ class oneperType02_2(GeneratedsSuper):
             eol_ = ''
         if self.clientdescription is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sclientdescription>%s</%sclientdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.clientdescription).encode(ExternalEncoding), input_name='clientdescription'), namespace_, eol_))
+            outfile.write('<%sclientdescription>%s</%sclientdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.clientdescription), input_name='clientdescription')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/OnePer/oneperType02_2One.py b/tests/OnePer/oneperType02_2One.py
index d477ecea9763303bc135f9b9650e8de4ebec7876..339dabeb4899224541cf1af0be07661fe3c301ab 100644
--- a/tests/OnePer/oneperType02_2One.py
+++ b/tests/OnePer/oneperType02_2One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class oneperType02_1(GeneratedsSuper):
             eol_ = ''
         if self.clientname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sclientname>%s</%sclientname>%s' % (namespace_, self.gds_format_string(quote_xml(self.clientname).encode(ExternalEncoding), input_name='clientname'), namespace_, eol_))
+            outfile.write('<%sclientname>%s</%sclientname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.clientname), input_name='clientname')), namespace_, eol_))
         if self.inner01 is not None:
             self.inner01.export(outfile, level, namespace_, name_='inner01', pretty_print=pretty_print)
     def build(self, node):
@@ -776,7 +786,7 @@ class oneperType02_2(GeneratedsSuper):
             eol_ = ''
         if self.clientdescription is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sclientdescription>%s</%sclientdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.clientdescription).encode(ExternalEncoding), input_name='clientdescription'), namespace_, eol_))
+            outfile.write('<%sclientdescription>%s</%sclientdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.clientdescription), input_name='clientdescription')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/OnePer/oneperType03_1One.py b/tests/OnePer/oneperType03_1One.py
index 3dc877eaa52f9c35e3365bf9885ac86e5c5c2021..809e00c7b9d0e8d90330b02a0add9262619bd295 100644
--- a/tests/OnePer/oneperType03_1One.py
+++ b/tests/OnePer/oneperType03_1One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class oneperType03_1(GeneratedsSuper):
             eol_ = ''
         if self.helpername is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%shelpername>%s</%shelpername>%s' % (namespace_, self.gds_format_string(quote_xml(self.helpername).encode(ExternalEncoding), input_name='helpername'), namespace_, eol_))
+            outfile.write('<%shelpername>%s</%shelpername>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.helpername), input_name='helpername')), namespace_, eol_))
         if self.inner01 is not None:
             self.inner01.export(outfile, level, namespace_, name_='inner01', pretty_print=pretty_print)
     def build(self, node):
@@ -776,7 +786,7 @@ class oneperType03_2(GeneratedsSuper):
             eol_ = ''
         if self.helperdescription is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%shelperdescription>%s</%shelperdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.helperdescription).encode(ExternalEncoding), input_name='helperdescription'), namespace_, eol_))
+            outfile.write('<%shelperdescription>%s</%shelperdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.helperdescription), input_name='helperdescription')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/OnePer/oneperType03_2One.py b/tests/OnePer/oneperType03_2One.py
index 3dc877eaa52f9c35e3365bf9885ac86e5c5c2021..809e00c7b9d0e8d90330b02a0add9262619bd295 100644
--- a/tests/OnePer/oneperType03_2One.py
+++ b/tests/OnePer/oneperType03_2One.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class oneperType03_1(GeneratedsSuper):
             eol_ = ''
         if self.helpername is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%shelpername>%s</%shelpername>%s' % (namespace_, self.gds_format_string(quote_xml(self.helpername).encode(ExternalEncoding), input_name='helpername'), namespace_, eol_))
+            outfile.write('<%shelpername>%s</%shelpername>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.helpername), input_name='helpername')), namespace_, eol_))
         if self.inner01 is not None:
             self.inner01.export(outfile, level, namespace_, name_='inner01', pretty_print=pretty_print)
     def build(self, node):
@@ -776,7 +786,7 @@ class oneperType03_2(GeneratedsSuper):
             eol_ = ''
         if self.helperdescription is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%shelperdescription>%s</%shelperdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.helperdescription).encode(ExternalEncoding), input_name='helperdescription'), namespace_, eol_))
+            outfile.write('<%shelperdescription>%s</%shelperdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.helperdescription), input_name='helperdescription')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/abstract_type1_sup.py b/tests/abstract_type1_sup.py
index d4fc7d325fa63b417768ac4d0b28aea301653e45..d8510aebf738ff9130d2c80ac382529bf8e7d05f 100644
--- a/tests/abstract_type1_sup.py
+++ b/tests/abstract_type1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
diff --git a/tests/abstract_type2_sup.py b/tests/abstract_type2_sup.py
index d4fc7d325fa63b417768ac4d0b28aea301653e45..d8510aebf738ff9130d2c80ac382529bf8e7d05f 100644
--- a/tests/abstract_type2_sup.py
+++ b/tests/abstract_type2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
diff --git a/tests/annotations1_sup.py b/tests/annotations1_sup.py
index 5069103ed0355215f6758fb58964f62ea5e8253d..6071f59b7e0f6333f7e303fedfd672fcffc5fc58 100644
--- a/tests/annotations1_sup.py
+++ b/tests/annotations1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -697,7 +707,7 @@ class document1Type(GeneratedsSuper):
             eol_ = ''
         if self.comments is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_format_string(quote_xml(self.comments).encode(ExternalEncoding), input_name='comments'), namespace_, eol_))
+            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.comments), input_name='comments')), namespace_, eol_))
         if self.otherdoc is not None:
             self.otherdoc.export(outfile, level, namespace_, name_='otherdoc', pretty_print=pretty_print)
     def build(self, node):
@@ -791,7 +801,7 @@ class document2Type(GeneratedsSuper):
             eol_ = ''
         if self.comments is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_format_string(quote_xml(self.comments).encode(ExternalEncoding), input_name='comments'), namespace_, eol_))
+            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.comments), input_name='comments')), namespace_, eol_))
         if self.rating is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srating>%s</%srating>%s' % (namespace_, self.gds_format_integer(self.rating, input_name='rating'), namespace_, eol_))
@@ -889,7 +899,7 @@ class document3Type(GeneratedsSuper):
             eol_ = ''
         if self.comments is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_format_string(quote_xml(self.comments).encode(ExternalEncoding), input_name='comments'), namespace_, eol_))
+            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.comments), input_name='comments')), namespace_, eol_))
         if self.rating is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srating>%s</%srating>%s' % (namespace_, self.gds_format_integer(self.rating, input_name='rating'), namespace_, eol_))
diff --git a/tests/annotations2_sup.py b/tests/annotations2_sup.py
index 5069103ed0355215f6758fb58964f62ea5e8253d..6071f59b7e0f6333f7e303fedfd672fcffc5fc58 100644
--- a/tests/annotations2_sup.py
+++ b/tests/annotations2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -697,7 +707,7 @@ class document1Type(GeneratedsSuper):
             eol_ = ''
         if self.comments is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_format_string(quote_xml(self.comments).encode(ExternalEncoding), input_name='comments'), namespace_, eol_))
+            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.comments), input_name='comments')), namespace_, eol_))
         if self.otherdoc is not None:
             self.otherdoc.export(outfile, level, namespace_, name_='otherdoc', pretty_print=pretty_print)
     def build(self, node):
@@ -791,7 +801,7 @@ class document2Type(GeneratedsSuper):
             eol_ = ''
         if self.comments is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_format_string(quote_xml(self.comments).encode(ExternalEncoding), input_name='comments'), namespace_, eol_))
+            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.comments), input_name='comments')), namespace_, eol_))
         if self.rating is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srating>%s</%srating>%s' % (namespace_, self.gds_format_integer(self.rating, input_name='rating'), namespace_, eol_))
@@ -889,7 +899,7 @@ class document3Type(GeneratedsSuper):
             eol_ = ''
         if self.comments is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_format_string(quote_xml(self.comments).encode(ExternalEncoding), input_name='comments'), namespace_, eol_))
+            outfile.write('<%scomments>%s</%scomments>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.comments), input_name='comments')), namespace_, eol_))
         if self.rating is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srating>%s</%srating>%s' % (namespace_, self.gds_format_integer(self.rating, input_name='rating'), namespace_, eol_))
diff --git a/tests/anonymous_type1_sup.py b/tests/anonymous_type1_sup.py
index 107e6d68b76a45e010ecfd75d9d35ce2a6085e5b..9aed0dfe829c75bc3c2a2f2cd096169da484254c 100644
--- a/tests/anonymous_type1_sup.py
+++ b/tests/anonymous_type1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -795,7 +805,7 @@ class FooType1(GeneratedsSuper):
             eol_ = ''
         if self.FooType is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sFooType>%s</%sFooType>%s' % (namespace_, self.gds_format_string(quote_xml(self.FooType).encode(ExternalEncoding), input_name='FooType'), namespace_, eol_))
+            outfile.write('<%sFooType>%s</%sFooType>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.FooType), input_name='FooType')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -879,7 +889,7 @@ class BarType2(GeneratedsSuper):
             eol_ = ''
         if self.BarType is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sBarType>%s</%sBarType>%s' % (namespace_, self.gds_format_string(quote_xml(self.BarType).encode(ExternalEncoding), input_name='BarType'), namespace_, eol_))
+            outfile.write('<%sBarType>%s</%sBarType>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.BarType), input_name='BarType')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -963,7 +973,7 @@ class BazType3(GeneratedsSuper):
             eol_ = ''
         if self.BazType is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sBazType>%s</%sBazType>%s' % (namespace_, self.gds_format_string(quote_xml(self.BazType).encode(ExternalEncoding), input_name='BazType'), namespace_, eol_))
+            outfile.write('<%sBazType>%s</%sBazType>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.BazType), input_name='BazType')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/anonymous_type2_sup.py b/tests/anonymous_type2_sup.py
index 107e6d68b76a45e010ecfd75d9d35ce2a6085e5b..9aed0dfe829c75bc3c2a2f2cd096169da484254c 100644
--- a/tests/anonymous_type2_sup.py
+++ b/tests/anonymous_type2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -795,7 +805,7 @@ class FooType1(GeneratedsSuper):
             eol_ = ''
         if self.FooType is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sFooType>%s</%sFooType>%s' % (namespace_, self.gds_format_string(quote_xml(self.FooType).encode(ExternalEncoding), input_name='FooType'), namespace_, eol_))
+            outfile.write('<%sFooType>%s</%sFooType>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.FooType), input_name='FooType')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -879,7 +889,7 @@ class BarType2(GeneratedsSuper):
             eol_ = ''
         if self.BarType is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sBarType>%s</%sBarType>%s' % (namespace_, self.gds_format_string(quote_xml(self.BarType).encode(ExternalEncoding), input_name='BarType'), namespace_, eol_))
+            outfile.write('<%sBarType>%s</%sBarType>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.BarType), input_name='BarType')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -963,7 +973,7 @@ class BazType3(GeneratedsSuper):
             eol_ = ''
         if self.BazType is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sBazType>%s</%sBazType>%s' % (namespace_, self.gds_format_string(quote_xml(self.BazType).encode(ExternalEncoding), input_name='BazType'), namespace_, eol_))
+            outfile.write('<%sBazType>%s</%sBazType>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.BazType), input_name='BazType')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/anysimpletype1_sup.py b/tests/anysimpletype1_sup.py
index 2499ac8c3df751253e7e2398efa1572e2b9023d8..4dd47d745727078c73378ccec04521fde44f0085 100644
--- a/tests/anysimpletype1_sup.py
+++ b/tests/anysimpletype1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -761,7 +771,7 @@ class cimAnySimpleType(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='cimAnySimpleType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='cimAnySimpleType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
diff --git a/tests/anysimpletype2_sup.py b/tests/anysimpletype2_sup.py
index 2499ac8c3df751253e7e2398efa1572e2b9023d8..4dd47d745727078c73378ccec04521fde44f0085 100644
--- a/tests/anysimpletype2_sup.py
+++ b/tests/anysimpletype2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -761,7 +771,7 @@ class cimAnySimpleType(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='cimAnySimpleType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='cimAnySimpleType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
diff --git a/tests/anywildcard1_sup.py b/tests/anywildcard1_sup.py
index 6a3fd36ef0f252a6996c6bab976e15f19e1507bc..a67df98af6e94bb88ef6ed25b0ce77722a3fcd23 100644
--- a/tests/anywildcard1_sup.py
+++ b/tests/anywildcard1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -699,7 +709,7 @@ class PlantType_single(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.description is not None:
             self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
         if self.anytypeobjs_ is not None:
@@ -801,7 +811,7 @@ class PlantType_multiple(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.description is not None:
             self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
         for obj_ in self.anytypeobjs_:
@@ -894,10 +904,10 @@ class DescriptionType(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.size is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%ssize>%s</%ssize>%s' % (namespace_, self.gds_format_string(quote_xml(self.size).encode(ExternalEncoding), input_name='size'), namespace_, eol_))
+            outfile.write('<%ssize>%s</%ssize>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.size), input_name='size')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -981,7 +991,7 @@ class CatalogType(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.catagory is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scatagory>%s</%scatagory>%s' % (namespace_, self.gds_format_integer(self.catagory, input_name='catagory'), namespace_, eol_))
diff --git a/tests/anywildcard2_sup.py b/tests/anywildcard2_sup.py
index 6a3fd36ef0f252a6996c6bab976e15f19e1507bc..a67df98af6e94bb88ef6ed25b0ce77722a3fcd23 100644
--- a/tests/anywildcard2_sup.py
+++ b/tests/anywildcard2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -699,7 +709,7 @@ class PlantType_single(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.description is not None:
             self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
         if self.anytypeobjs_ is not None:
@@ -801,7 +811,7 @@ class PlantType_multiple(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.description is not None:
             self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
         for obj_ in self.anytypeobjs_:
@@ -894,10 +904,10 @@ class DescriptionType(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.size is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%ssize>%s</%ssize>%s' % (namespace_, self.gds_format_string(quote_xml(self.size).encode(ExternalEncoding), input_name='size'), namespace_, eol_))
+            outfile.write('<%ssize>%s</%ssize>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.size), input_name='size')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -981,7 +991,7 @@ class CatalogType(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         if self.catagory is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scatagory>%s</%scatagory>%s' % (namespace_, self.gds_format_integer(self.catagory, input_name='catagory'), namespace_, eol_))
diff --git a/tests/attr_groups1_sup.py b/tests/attr_groups1_sup.py
index d038363bccd8383dc1815a58a78b0827f0aa648e..3a65b3fe265d1abc4fad2fd894e4c70ef323567d 100644
--- a/tests/attr_groups1_sup.py
+++ b/tests/attr_groups1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -718,19 +728,19 @@ class GetUserReq(GeneratedsSuper):
             outfile.write(' sequence="%s"' % self.gds_format_integer(self.sequence, input_name='sequence'))
         if self.value01 is not None and 'value01' not in already_processed:
             already_processed.add('value01')
-            outfile.write(' value01=%s' % (self.gds_format_string(quote_attrib(self.value01).encode(ExternalEncoding), input_name='value01'), ))
+            outfile.write(' value01=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value01), input_name='value01')), ))
         if self.value02 is not None and 'value02' not in already_processed:
             already_processed.add('value02')
             outfile.write(' value02="%s"' % self.gds_format_integer(self.value02, input_name='value02'))
         if self.value03 is not None and 'value03' not in already_processed:
             already_processed.add('value03')
-            outfile.write(' value03=%s' % (self.gds_format_string(quote_attrib(self.value03).encode(ExternalEncoding), input_name='value03'), ))
+            outfile.write(' value03=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value03), input_name='value03')), ))
         if self.value04 is not None and 'value04' not in already_processed:
             already_processed.add('value04')
             outfile.write(' value04="%s"' % self.gds_format_integer(self.value04, input_name='value04'))
         if self.value05 is not None and 'value05' not in already_processed:
             already_processed.add('value05')
-            outfile.write(' value05=%s' % (self.gds_format_string(quote_attrib(self.value05).encode(ExternalEncoding), input_name='value05'), ))
+            outfile.write(' value05=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value05), input_name='value05')), ))
         if self.value06 is not None and 'value06' not in already_processed:
             already_processed.add('value06')
             outfile.write(' value06="%s"' % self.gds_format_integer(self.value06, input_name='value06'))
@@ -744,7 +754,7 @@ class GetUserReq(GeneratedsSuper):
             eol_ = ''
         if self.returnedTags is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sreturnedTags>%s</%sreturnedTags>%s' % (namespace_, self.gds_format_string(quote_xml(self.returnedTags).encode(ExternalEncoding), input_name='returnedTags'), namespace_, eol_))
+            outfile.write('<%sreturnedTags>%s</%sreturnedTags>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.returnedTags), input_name='returnedTags')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/attr_groups2_sup.py b/tests/attr_groups2_sup.py
index d038363bccd8383dc1815a58a78b0827f0aa648e..3a65b3fe265d1abc4fad2fd894e4c70ef323567d 100644
--- a/tests/attr_groups2_sup.py
+++ b/tests/attr_groups2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -718,19 +728,19 @@ class GetUserReq(GeneratedsSuper):
             outfile.write(' sequence="%s"' % self.gds_format_integer(self.sequence, input_name='sequence'))
         if self.value01 is not None and 'value01' not in already_processed:
             already_processed.add('value01')
-            outfile.write(' value01=%s' % (self.gds_format_string(quote_attrib(self.value01).encode(ExternalEncoding), input_name='value01'), ))
+            outfile.write(' value01=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value01), input_name='value01')), ))
         if self.value02 is not None and 'value02' not in already_processed:
             already_processed.add('value02')
             outfile.write(' value02="%s"' % self.gds_format_integer(self.value02, input_name='value02'))
         if self.value03 is not None and 'value03' not in already_processed:
             already_processed.add('value03')
-            outfile.write(' value03=%s' % (self.gds_format_string(quote_attrib(self.value03).encode(ExternalEncoding), input_name='value03'), ))
+            outfile.write(' value03=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value03), input_name='value03')), ))
         if self.value04 is not None and 'value04' not in already_processed:
             already_processed.add('value04')
             outfile.write(' value04="%s"' % self.gds_format_integer(self.value04, input_name='value04'))
         if self.value05 is not None and 'value05' not in already_processed:
             already_processed.add('value05')
-            outfile.write(' value05=%s' % (self.gds_format_string(quote_attrib(self.value05).encode(ExternalEncoding), input_name='value05'), ))
+            outfile.write(' value05=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value05), input_name='value05')), ))
         if self.value06 is not None and 'value06' not in already_processed:
             already_processed.add('value06')
             outfile.write(' value06="%s"' % self.gds_format_integer(self.value06, input_name='value06'))
@@ -744,7 +754,7 @@ class GetUserReq(GeneratedsSuper):
             eol_ = ''
         if self.returnedTags is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sreturnedTags>%s</%sreturnedTags>%s' % (namespace_, self.gds_format_string(quote_xml(self.returnedTags).encode(ExternalEncoding), input_name='returnedTags'), namespace_, eol_))
+            outfile.write('<%sreturnedTags>%s</%sreturnedTags>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.returnedTags), input_name='returnedTags')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/cdata1_sup.py b/tests/cdata1_sup.py
index fb1228a5ae775a54452671591801b99c28f406f8..481512927632ba9520e5817fb88764c483dd74f5 100644
--- a/tests/cdata1_sup.py
+++ b/tests/cdata1_sup.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -770,7 +780,7 @@ class cdataType(GeneratedsSuper):
             eol_ = ''
         if self.script is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sscript>%s</%sscript>%s' % (namespace_, self.gds_format_string(quote_xml(self.script).encode(ExternalEncoding), input_name='script'), namespace_, eol_))
+            outfile.write('<%sscript>%s</%sscript>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.script), input_name='script')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/cdata2_sup.py b/tests/cdata2_sup.py
index fb1228a5ae775a54452671591801b99c28f406f8..481512927632ba9520e5817fb88764c483dd74f5 100644
--- a/tests/cdata2_sup.py
+++ b/tests/cdata2_sup.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -770,7 +780,7 @@ class cdataType(GeneratedsSuper):
             eol_ = ''
         if self.script is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sscript>%s</%sscript>%s' % (namespace_, self.gds_format_string(quote_xml(self.script).encode(ExternalEncoding), input_name='script'), namespace_, eol_))
+            outfile.write('<%sscript>%s</%sscript>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.script), input_name='script')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/cleanupname1_sup.py b/tests/cleanupname1_sup.py
index 38b495b664629520801f374fd12fa0797693e005..9d3b8c8cd40b978b771635986ebdb2d2fcdffb9e 100644
--- a/tests/cleanupname1_sup.py
+++ b/tests/cleanupname1_sup.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -812,7 +822,7 @@ class data1Kind(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -886,7 +896,7 @@ class MlassData2(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -960,7 +970,7 @@ class RealTypeData3(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1034,7 +1044,7 @@ class MMMMMMdataKind(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1108,7 +1118,7 @@ class dataTypeNNNMNNN(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/cleanupname2_sup.py b/tests/cleanupname2_sup.py
index 38b495b664629520801f374fd12fa0797693e005..9d3b8c8cd40b978b771635986ebdb2d2fcdffb9e 100644
--- a/tests/cleanupname2_sup.py
+++ b/tests/cleanupname2_sup.py
@@ -34,6 +34,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -353,6 +357,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -407,7 +417,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -429,7 +439,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -812,7 +822,7 @@ class data1Kind(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -886,7 +896,7 @@ class MlassData2(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -960,7 +970,7 @@ class RealTypeData3(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1034,7 +1044,7 @@ class MMMMMMdataKind(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1108,7 +1118,7 @@ class dataTypeNNNMNNN(GeneratedsSuper):
             eol_ = ''
         if self.content1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_format_string(quote_xml(self.content1).encode(ExternalEncoding), input_name='content1'), namespace_, eol_))
+            outfile.write('<%scontent1>%s</%scontent1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.content1), input_name='content1')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/defaults_cases1_out.xml b/tests/defaults_cases1_out.xml
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..58064fbb71077e954ce44c50c45802e4de17038b 100644
--- a/tests/defaults_cases1_out.xml
+++ b/tests/defaults_cases1_out.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<defaults>
+    <default1>
+        <normal02>a new value 1</normal02>
+        <default02>a new value 2</default02>
+        <normal03>55.659999999999997</normal03>
+        <normal04>6.677000e+01</normal04>
+        <default03>77.879999999999995</default03>
+        <default04>8.899000e+01</default04>
+    </default1>
+    <default2 attrdefault01="xyz"/>
+    <default2/>
+    <default2/>
+    <default2 attrnormal01="wxy"/>
+    <default2 attrnormal02="89"/>
+</defaults>
diff --git a/tests/defaults_cases1_sub.py b/tests/defaults_cases1_sub.py
index ad19fc66270089487a5b291955a2d271f7f6db5c..3e60267cdf12461a2291918650fa77850b395405 100644
--- a/tests/defaults_cases1_sub.py
+++ b/tests/defaults_cases1_sub.py
@@ -6,7 +6,6 @@
 # Command line options:
 #   ('--no-dates', '')
 #   ('--no-versions', '')
-#   ('--silence', '')
 #   ('--member-specs', 'list')
 #   ('-f', '')
 #   ('-o', 'tests/defaults_cases2_sup.py')
@@ -17,7 +16,7 @@
 #   tests/defaults_cases.xsd
 #
 # Command line:
-#   generateDS.py --no-dates --no-versions --silence --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
+#   generateDS.py --no-dates --no-versions --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
 #
 # Current working directory (os.getcwd()):
 #   generateds
@@ -89,12 +88,12 @@ def parse(inFilename, silence=False):
     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)
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='',
+            pretty_print=True)
     return rootObj
 
 
@@ -113,12 +112,12 @@ def parseEtree(inFilename, silence=False):
     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')
+    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
 
 
@@ -135,11 +134,11 @@ def parseString(inString, silence=False):
     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_='')
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='')
     return rootObj
 
 
@@ -155,12 +154,12 @@ def parseLiteral(inFilename, silence=False):
     rootObj.build(rootNode)
     # Enable Python to collect the space used by the DOM.
     doc = None
-##     if not silence:
-##         sys.stdout.write('#from defaults_cases2_sup import *\n\n')
-##         sys.stdout.write('import defaults_cases2_sup as model_\n\n')
-##         sys.stdout.write('rootObj = model_.rootClass(\n')
-##         rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
-##         sys.stdout.write(')\n')
+    if not silence:
+        sys.stdout.write('#from defaults_cases2_sup import *\n\n')
+        sys.stdout.write('import defaults_cases2_sup as model_\n\n')
+        sys.stdout.write('rootObj = model_.rootClass(\n')
+        rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
+        sys.stdout.write(')\n')
     return rootObj
 
 
diff --git a/tests/defaults_cases1_sup.py b/tests/defaults_cases1_sup.py
index 3f73c5d79d3fdb6066e7efa2775c7501df09649c..d9f5a13991cbbf3b2a0e7e549d5a31af79bae089 100644
--- a/tests/defaults_cases1_sup.py
+++ b/tests/defaults_cases1_sup.py
@@ -7,7 +7,6 @@
 # Command line options:
 #   ('--no-dates', '')
 #   ('--no-versions', '')
-#   ('--silence', '')
 #   ('--member-specs', 'list')
 #   ('-f', '')
 #   ('-o', 'tests/defaults_cases2_sup.py')
@@ -18,7 +17,7 @@
 #   tests/defaults_cases.xsd
 #
 # Command line:
-#   generateDS.py --no-dates --no-versions --silence --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
+#   generateDS.py --no-dates --no-versions --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
 #
 # Current working directory (os.getcwd()):
 #   generateds
@@ -33,6 +32,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +355,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +415,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +437,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -825,13 +834,13 @@ class DefaultType1(GeneratedsSuper):
             outfile.write('<%snormal01>%s</%snormal01>%s' % (namespace_, self.gds_format_integer(self.normal01, input_name='normal01'), namespace_, eol_))
         if self.normal02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_format_string(quote_xml(self.normal02).encode(ExternalEncoding), input_name='normal02'), namespace_, eol_))
+            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.normal02), input_name='normal02')), namespace_, eol_))
         if self.default01 != 23:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sdefault01>%s</%sdefault01>%s' % (namespace_, self.gds_format_integer(self.default01, input_name='default01'), namespace_, eol_))
         if self.default02 != "Peach":
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_format_string(quote_xml(self.default02).encode(ExternalEncoding), input_name='default02'), namespace_, eol_))
+            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.default02), input_name='default02')), namespace_, eol_))
         if self.normal03 is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%snormal03>%s</%snormal03>%s' % (namespace_, self.gds_format_float(self.normal03, input_name='normal03'), namespace_, eol_))
@@ -974,13 +983,13 @@ class DefaultType2(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='DefaultType2'):
         if self.attrdefault01 != "abcd" and 'attrdefault01' not in already_processed:
             already_processed.add('attrdefault01')
-            outfile.write(' attrdefault01=%s' % (self.gds_format_string(quote_attrib(self.attrdefault01).encode(ExternalEncoding), input_name='attrdefault01'), ))
+            outfile.write(' attrdefault01=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrdefault01), input_name='attrdefault01')), ))
         if self.attrdefault02 != 14 and 'attrdefault02' not in already_processed:
             already_processed.add('attrdefault02')
             outfile.write(' attrdefault02="%s"' % self.gds_format_integer(self.attrdefault02, input_name='attrdefault02'))
         if self.attrnormal01 is not None and 'attrnormal01' not in already_processed:
             already_processed.add('attrnormal01')
-            outfile.write(' attrnormal01=%s' % (self.gds_format_string(quote_attrib(self.attrnormal01).encode(ExternalEncoding), input_name='attrnormal01'), ))
+            outfile.write(' attrnormal01=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrnormal01), input_name='attrnormal01')), ))
         if self.attrnormal02 is not None and 'attrnormal02' not in already_processed:
             already_processed.add('attrnormal02')
             outfile.write(' attrnormal02="%s"' % self.gds_format_integer(self.attrnormal02, input_name='attrnormal02'))
@@ -1058,12 +1067,12 @@ def parse(inFileName, silence=False):
     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)
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='',
+            pretty_print=True)
     return rootObj
 
 
@@ -1082,12 +1091,12 @@ def parseEtree(inFileName, silence=False):
     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')
+    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
 
 
@@ -1104,11 +1113,11 @@ def parseString(inString, silence=False):
     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_='')
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='')
     return rootObj
 
 
@@ -1124,12 +1133,12 @@ def parseLiteral(inFileName, silence=False):
     rootObj.build(rootNode)
     # Enable Python to collect the space used by the DOM.
     doc = None
-##     if not silence:
-##         sys.stdout.write('#from defaults_cases2_sup import *\n\n')
-##         sys.stdout.write('import defaults_cases2_sup as model_\n\n')
-##         sys.stdout.write('rootObj = model_.rootClass(\n')
-##         rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
-##         sys.stdout.write(')\n')
+    if not silence:
+        sys.stdout.write('#from defaults_cases2_sup import *\n\n')
+        sys.stdout.write('import defaults_cases2_sup as model_\n\n')
+        sys.stdout.write('rootObj = model_.rootClass(\n')
+        rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
+        sys.stdout.write(')\n')
     return rootObj
 
 
diff --git a/tests/defaults_cases2_out.xml b/tests/defaults_cases2_out.xml
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..58064fbb71077e954ce44c50c45802e4de17038b 100644
--- a/tests/defaults_cases2_out.xml
+++ b/tests/defaults_cases2_out.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<defaults>
+    <default1>
+        <normal02>a new value 1</normal02>
+        <default02>a new value 2</default02>
+        <normal03>55.659999999999997</normal03>
+        <normal04>6.677000e+01</normal04>
+        <default03>77.879999999999995</default03>
+        <default04>8.899000e+01</default04>
+    </default1>
+    <default2 attrdefault01="xyz"/>
+    <default2/>
+    <default2/>
+    <default2 attrnormal01="wxy"/>
+    <default2 attrnormal02="89"/>
+</defaults>
diff --git a/tests/defaults_cases2_sub.py b/tests/defaults_cases2_sub.py
index ad19fc66270089487a5b291955a2d271f7f6db5c..3e60267cdf12461a2291918650fa77850b395405 100644
--- a/tests/defaults_cases2_sub.py
+++ b/tests/defaults_cases2_sub.py
@@ -6,7 +6,6 @@
 # Command line options:
 #   ('--no-dates', '')
 #   ('--no-versions', '')
-#   ('--silence', '')
 #   ('--member-specs', 'list')
 #   ('-f', '')
 #   ('-o', 'tests/defaults_cases2_sup.py')
@@ -17,7 +16,7 @@
 #   tests/defaults_cases.xsd
 #
 # Command line:
-#   generateDS.py --no-dates --no-versions --silence --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
+#   generateDS.py --no-dates --no-versions --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
 #
 # Current working directory (os.getcwd()):
 #   generateds
@@ -89,12 +88,12 @@ def parse(inFilename, silence=False):
     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)
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='',
+            pretty_print=True)
     return rootObj
 
 
@@ -113,12 +112,12 @@ def parseEtree(inFilename, silence=False):
     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')
+    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
 
 
@@ -135,11 +134,11 @@ def parseString(inString, silence=False):
     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_='')
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='')
     return rootObj
 
 
@@ -155,12 +154,12 @@ def parseLiteral(inFilename, silence=False):
     rootObj.build(rootNode)
     # Enable Python to collect the space used by the DOM.
     doc = None
-##     if not silence:
-##         sys.stdout.write('#from defaults_cases2_sup import *\n\n')
-##         sys.stdout.write('import defaults_cases2_sup as model_\n\n')
-##         sys.stdout.write('rootObj = model_.rootClass(\n')
-##         rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
-##         sys.stdout.write(')\n')
+    if not silence:
+        sys.stdout.write('#from defaults_cases2_sup import *\n\n')
+        sys.stdout.write('import defaults_cases2_sup as model_\n\n')
+        sys.stdout.write('rootObj = model_.rootClass(\n')
+        rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
+        sys.stdout.write(')\n')
     return rootObj
 
 
diff --git a/tests/defaults_cases2_sup.py b/tests/defaults_cases2_sup.py
index 3f73c5d79d3fdb6066e7efa2775c7501df09649c..d9f5a13991cbbf3b2a0e7e549d5a31af79bae089 100644
--- a/tests/defaults_cases2_sup.py
+++ b/tests/defaults_cases2_sup.py
@@ -7,7 +7,6 @@
 # Command line options:
 #   ('--no-dates', '')
 #   ('--no-versions', '')
-#   ('--silence', '')
 #   ('--member-specs', 'list')
 #   ('-f', '')
 #   ('-o', 'tests/defaults_cases2_sup.py')
@@ -18,7 +17,7 @@
 #   tests/defaults_cases.xsd
 #
 # Command line:
-#   generateDS.py --no-dates --no-versions --silence --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
+#   generateDS.py --no-dates --no-versions --member-specs="list" -f -o "tests/defaults_cases2_sup.py" -s "tests/defaults_cases2_sub.py" --super="defaults_cases2_sup" tests/defaults_cases.xsd
 #
 # Current working directory (os.getcwd()):
 #   generateds
@@ -33,6 +32,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +355,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +415,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +437,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -825,13 +834,13 @@ class DefaultType1(GeneratedsSuper):
             outfile.write('<%snormal01>%s</%snormal01>%s' % (namespace_, self.gds_format_integer(self.normal01, input_name='normal01'), namespace_, eol_))
         if self.normal02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_format_string(quote_xml(self.normal02).encode(ExternalEncoding), input_name='normal02'), namespace_, eol_))
+            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.normal02), input_name='normal02')), namespace_, eol_))
         if self.default01 != 23:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sdefault01>%s</%sdefault01>%s' % (namespace_, self.gds_format_integer(self.default01, input_name='default01'), namespace_, eol_))
         if self.default02 != "Peach":
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_format_string(quote_xml(self.default02).encode(ExternalEncoding), input_name='default02'), namespace_, eol_))
+            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.default02), input_name='default02')), namespace_, eol_))
         if self.normal03 is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%snormal03>%s</%snormal03>%s' % (namespace_, self.gds_format_float(self.normal03, input_name='normal03'), namespace_, eol_))
@@ -974,13 +983,13 @@ class DefaultType2(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='DefaultType2'):
         if self.attrdefault01 != "abcd" and 'attrdefault01' not in already_processed:
             already_processed.add('attrdefault01')
-            outfile.write(' attrdefault01=%s' % (self.gds_format_string(quote_attrib(self.attrdefault01).encode(ExternalEncoding), input_name='attrdefault01'), ))
+            outfile.write(' attrdefault01=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrdefault01), input_name='attrdefault01')), ))
         if self.attrdefault02 != 14 and 'attrdefault02' not in already_processed:
             already_processed.add('attrdefault02')
             outfile.write(' attrdefault02="%s"' % self.gds_format_integer(self.attrdefault02, input_name='attrdefault02'))
         if self.attrnormal01 is not None and 'attrnormal01' not in already_processed:
             already_processed.add('attrnormal01')
-            outfile.write(' attrnormal01=%s' % (self.gds_format_string(quote_attrib(self.attrnormal01).encode(ExternalEncoding), input_name='attrnormal01'), ))
+            outfile.write(' attrnormal01=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrnormal01), input_name='attrnormal01')), ))
         if self.attrnormal02 is not None and 'attrnormal02' not in already_processed:
             already_processed.add('attrnormal02')
             outfile.write(' attrnormal02="%s"' % self.gds_format_integer(self.attrnormal02, input_name='attrnormal02'))
@@ -1058,12 +1067,12 @@ def parse(inFileName, silence=False):
     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)
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='',
+            pretty_print=True)
     return rootObj
 
 
@@ -1082,12 +1091,12 @@ def parseEtree(inFileName, silence=False):
     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')
+    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
 
 
@@ -1104,11 +1113,11 @@ def parseString(inString, silence=False):
     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_='')
+    if not silence:
+        sys.stdout.write('<?xml version="1.0" ?>\n')
+        rootObj.export(
+            sys.stdout, 0, name_=rootTag,
+            namespacedef_='')
     return rootObj
 
 
@@ -1124,12 +1133,12 @@ def parseLiteral(inFileName, silence=False):
     rootObj.build(rootNode)
     # Enable Python to collect the space used by the DOM.
     doc = None
-##     if not silence:
-##         sys.stdout.write('#from defaults_cases2_sup import *\n\n')
-##         sys.stdout.write('import defaults_cases2_sup as model_\n\n')
-##         sys.stdout.write('rootObj = model_.rootClass(\n')
-##         rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
-##         sys.stdout.write(')\n')
+    if not silence:
+        sys.stdout.write('#from defaults_cases2_sup import *\n\n')
+        sys.stdout.write('import defaults_cases2_sup as model_\n\n')
+        sys.stdout.write('rootObj = model_.rootClass(\n')
+        rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
+        sys.stdout.write(')\n')
     return rootObj
 
 
diff --git a/tests/defaults_coverage1_sup.py b/tests/defaults_coverage1_sup.py
index 8dac9902a794b21867d03ccc14b8bd306b40008a..4cb45d6cddd15f550920ad2af89daa534abdc31b 100644
--- a/tests/defaults_coverage1_sup.py
+++ b/tests/defaults_coverage1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -754,32 +764,32 @@ class DefaultType1(GeneratedsSuper):
         self.default05a = default05a
         self.default05b = default05b
         self.normal05 = normal05
-        if isinstance(default06, basestring):
+        if isinstance(default06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default06, '%Y-%m-%d').date()
         else:
             initvalue_ = default06
         self.default06 = initvalue_
-        if isinstance(normal06, basestring):
+        if isinstance(normal06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal06, '%Y-%m-%d').date()
         else:
             initvalue_ = normal06
         self.normal06 = initvalue_
-        if isinstance(default07, basestring):
+        if isinstance(default07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default07, '%H:%M:%S').time()
         else:
             initvalue_ = default07
         self.default07 = initvalue_
-        if isinstance(normal07, basestring):
+        if isinstance(normal07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal07, '%Y-%m-%d').date()
         else:
             initvalue_ = normal07
         self.normal07 = initvalue_
-        if isinstance(default08, basestring):
+        if isinstance(default08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = default08
         self.default08 = initvalue_
-        if isinstance(normal08, basestring):
+        if isinstance(normal08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = normal08
@@ -885,10 +895,10 @@ class DefaultType1(GeneratedsSuper):
             outfile.write('<%snormal01>%s</%snormal01>%s' % (namespace_, self.gds_format_integer(self.normal01, input_name='normal01'), namespace_, eol_))
         if self.default02 != "Peach":
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_format_string(quote_xml(self.default02).encode(ExternalEncoding), input_name='default02'), namespace_, eol_))
+            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.default02), input_name='default02')), namespace_, eol_))
         if self.normal02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_format_string(quote_xml(self.normal02).encode(ExternalEncoding), input_name='normal02'), namespace_, eol_))
+            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.normal02), input_name='normal02')), namespace_, eol_))
         if self.default03 != 23.45:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sdefault03>%s</%sdefault03>%s' % (namespace_, self.gds_format_float(self.default03, input_name='default03'), namespace_, eol_))
@@ -1086,32 +1096,32 @@ class DefaultType2(GeneratedsSuper):
         self.default05a = default05a
         self.default05b = default05b
         self.normal05 = normal05
-        if isinstance(default06, basestring):
+        if isinstance(default06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default06, '%Y-%m-%d').date()
         else:
             initvalue_ = default06
         self.default06 = initvalue_
-        if isinstance(normal06, basestring):
+        if isinstance(normal06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal06, '%Y-%m-%d').date()
         else:
             initvalue_ = normal06
         self.normal06 = initvalue_
-        if isinstance(default07, basestring):
+        if isinstance(default07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default07, '%H:%M:%S').time()
         else:
             initvalue_ = default07
         self.default07 = initvalue_
-        if isinstance(normal07, basestring):
+        if isinstance(normal07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal07, '%Y-%m-%d').date()
         else:
             initvalue_ = normal07
         self.normal07 = initvalue_
-        if isinstance(default08, basestring):
+        if isinstance(default08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = default08
         self.default08 = initvalue_
-        if isinstance(normal08, basestring):
+        if isinstance(normal08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = normal08
@@ -1217,10 +1227,10 @@ class DefaultType2(GeneratedsSuper):
             outfile.write('<%snormal01>%s</%snormal01>%s' % (namespace_, self.gds_format_integer(self.normal01, input_name='normal01'), namespace_, eol_))
         if self.default02 != "Peach":
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_format_string(quote_xml(self.default02).encode(ExternalEncoding), input_name='default02'), namespace_, eol_))
+            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.default02), input_name='default02')), namespace_, eol_))
         if self.normal02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_format_string(quote_xml(self.normal02).encode(ExternalEncoding), input_name='normal02'), namespace_, eol_))
+            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.normal02), input_name='normal02')), namespace_, eol_))
         if self.default03 != 23.45:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sdefault03>%s</%sdefault03>%s' % (namespace_, self.gds_format_float(self.default03, input_name='default03'), namespace_, eol_))
diff --git a/tests/defaults_coverage2_sup.py b/tests/defaults_coverage2_sup.py
index 8dac9902a794b21867d03ccc14b8bd306b40008a..4cb45d6cddd15f550920ad2af89daa534abdc31b 100644
--- a/tests/defaults_coverage2_sup.py
+++ b/tests/defaults_coverage2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -754,32 +764,32 @@ class DefaultType1(GeneratedsSuper):
         self.default05a = default05a
         self.default05b = default05b
         self.normal05 = normal05
-        if isinstance(default06, basestring):
+        if isinstance(default06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default06, '%Y-%m-%d').date()
         else:
             initvalue_ = default06
         self.default06 = initvalue_
-        if isinstance(normal06, basestring):
+        if isinstance(normal06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal06, '%Y-%m-%d').date()
         else:
             initvalue_ = normal06
         self.normal06 = initvalue_
-        if isinstance(default07, basestring):
+        if isinstance(default07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default07, '%H:%M:%S').time()
         else:
             initvalue_ = default07
         self.default07 = initvalue_
-        if isinstance(normal07, basestring):
+        if isinstance(normal07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal07, '%Y-%m-%d').date()
         else:
             initvalue_ = normal07
         self.normal07 = initvalue_
-        if isinstance(default08, basestring):
+        if isinstance(default08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = default08
         self.default08 = initvalue_
-        if isinstance(normal08, basestring):
+        if isinstance(normal08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = normal08
@@ -885,10 +895,10 @@ class DefaultType1(GeneratedsSuper):
             outfile.write('<%snormal01>%s</%snormal01>%s' % (namespace_, self.gds_format_integer(self.normal01, input_name='normal01'), namespace_, eol_))
         if self.default02 != "Peach":
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_format_string(quote_xml(self.default02).encode(ExternalEncoding), input_name='default02'), namespace_, eol_))
+            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.default02), input_name='default02')), namespace_, eol_))
         if self.normal02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_format_string(quote_xml(self.normal02).encode(ExternalEncoding), input_name='normal02'), namespace_, eol_))
+            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.normal02), input_name='normal02')), namespace_, eol_))
         if self.default03 != 23.45:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sdefault03>%s</%sdefault03>%s' % (namespace_, self.gds_format_float(self.default03, input_name='default03'), namespace_, eol_))
@@ -1086,32 +1096,32 @@ class DefaultType2(GeneratedsSuper):
         self.default05a = default05a
         self.default05b = default05b
         self.normal05 = normal05
-        if isinstance(default06, basestring):
+        if isinstance(default06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default06, '%Y-%m-%d').date()
         else:
             initvalue_ = default06
         self.default06 = initvalue_
-        if isinstance(normal06, basestring):
+        if isinstance(normal06, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal06, '%Y-%m-%d').date()
         else:
             initvalue_ = normal06
         self.normal06 = initvalue_
-        if isinstance(default07, basestring):
+        if isinstance(default07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default07, '%H:%M:%S').time()
         else:
             initvalue_ = default07
         self.default07 = initvalue_
-        if isinstance(normal07, basestring):
+        if isinstance(normal07, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal07, '%Y-%m-%d').date()
         else:
             initvalue_ = normal07
         self.normal07 = initvalue_
-        if isinstance(default08, basestring):
+        if isinstance(default08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(default08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = default08
         self.default08 = initvalue_
-        if isinstance(normal08, basestring):
+        if isinstance(normal08, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(normal08, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = normal08
@@ -1217,10 +1227,10 @@ class DefaultType2(GeneratedsSuper):
             outfile.write('<%snormal01>%s</%snormal01>%s' % (namespace_, self.gds_format_integer(self.normal01, input_name='normal01'), namespace_, eol_))
         if self.default02 != "Peach":
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_format_string(quote_xml(self.default02).encode(ExternalEncoding), input_name='default02'), namespace_, eol_))
+            outfile.write('<%sdefault02>%s</%sdefault02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.default02), input_name='default02')), namespace_, eol_))
         if self.normal02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_format_string(quote_xml(self.normal02).encode(ExternalEncoding), input_name='normal02'), namespace_, eol_))
+            outfile.write('<%snormal02>%s</%snormal02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.normal02), input_name='normal02')), namespace_, eol_))
         if self.default03 != 23.45:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sdefault03>%s</%sdefault03>%s' % (namespace_, self.gds_format_float(self.default03, input_name='default03'), namespace_, eol_))
diff --git a/tests/extensions1_sup.py b/tests/extensions1_sup.py
index 896e1b35477e1e0ebf3ecb72a9943eff3b306fdc..1521f636b115d9d730e0d539d4ab1c2ce1a6f36b 100644
--- a/tests/extensions1_sup.py
+++ b/tests/extensions1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -679,7 +689,7 @@ class SpecialDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='SpecialDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='SpecialDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -687,7 +697,7 @@ class SpecialDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='SpecialDate'):
         if self.SpecialProperty is not None and 'SpecialProperty' not in already_processed:
             already_processed.add('SpecialProperty')
-            outfile.write(' SpecialProperty=%s' % (self.gds_format_string(quote_attrib(self.SpecialProperty).encode(ExternalEncoding), input_name='SpecialProperty'), ))
+            outfile.write(' SpecialProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.SpecialProperty), input_name='SpecialProperty')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='SpecialDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -754,7 +764,7 @@ class ExtremeDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='ExtremeDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='ExtremeDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -762,7 +772,7 @@ class ExtremeDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='ExtremeDate'):
         if self.ExtremeProperty is not None and 'ExtremeProperty' not in already_processed:
             already_processed.add('ExtremeProperty')
-            outfile.write(' ExtremeProperty=%s' % (self.gds_format_string(quote_attrib(self.ExtremeProperty).encode(ExternalEncoding), input_name='ExtremeProperty'), ))
+            outfile.write(' ExtremeProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.ExtremeProperty), input_name='ExtremeProperty')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='ExtremeDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -829,7 +839,7 @@ class singleExtremeDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='singleExtremeDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='singleExtremeDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -837,7 +847,7 @@ class singleExtremeDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='singleExtremeDate'):
         if self.ExtremeProperty is not None and 'ExtremeProperty' not in already_processed:
             already_processed.add('ExtremeProperty')
-            outfile.write(' ExtremeProperty=%s' % (self.gds_format_string(quote_attrib(self.ExtremeProperty).encode(ExternalEncoding), input_name='ExtremeProperty'), ))
+            outfile.write(' ExtremeProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.ExtremeProperty), input_name='ExtremeProperty')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='singleExtremeDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1037,7 +1047,7 @@ class simpleFactoidType(GeneratedsSuper):
             eol_ = ''
         if self.relation is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%srelation>%s</%srelation>%s' % (namespace_, self.gds_format_string(quote_xml(self.relation).encode(ExternalEncoding), input_name='relation'), namespace_, eol_))
+            outfile.write('<%srelation>%s</%srelation>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.relation), input_name='relation')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1235,7 +1245,7 @@ class BaseType(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='BaseType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='BaseType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1243,10 +1253,10 @@ class BaseType(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='BaseType'):
         if self.BaseProperty1 is not None and 'BaseProperty1' not in already_processed:
             already_processed.add('BaseProperty1')
-            outfile.write(' BaseProperty1=%s' % (self.gds_format_string(quote_attrib(self.BaseProperty1).encode(ExternalEncoding), input_name='BaseProperty1'), ))
+            outfile.write(' BaseProperty1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.BaseProperty1), input_name='BaseProperty1')), ))
         if self.BaseProperty2 is not None and 'BaseProperty2' not in already_processed:
             already_processed.add('BaseProperty2')
-            outfile.write(' BaseProperty2=%s' % (self.gds_format_string(quote_attrib(self.BaseProperty2).encode(ExternalEncoding), input_name='BaseProperty2'), ))
+            outfile.write(' BaseProperty2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.BaseProperty2), input_name='BaseProperty2')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1331,7 +1341,7 @@ class DerivedType(BaseType):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='DerivedType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='DerivedType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1340,10 +1350,10 @@ class DerivedType(BaseType):
         super(DerivedType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='DerivedType')
         if self.DerivedProperty1 is not None and 'DerivedProperty1' not in already_processed:
             already_processed.add('DerivedProperty1')
-            outfile.write(' DerivedProperty1=%s' % (self.gds_format_string(quote_attrib(self.DerivedProperty1).encode(ExternalEncoding), input_name='DerivedProperty1'), ))
+            outfile.write(' DerivedProperty1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.DerivedProperty1), input_name='DerivedProperty1')), ))
         if self.DerivedProperty2 is not None and 'DerivedProperty2' not in already_processed:
             already_processed.add('DerivedProperty2')
-            outfile.write(' DerivedProperty2=%s' % (self.gds_format_string(quote_attrib(self.DerivedProperty2).encode(ExternalEncoding), input_name='DerivedProperty2'), ))
+            outfile.write(' DerivedProperty2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.DerivedProperty2), input_name='DerivedProperty2')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='DerivedType', fromsubclass_=False, pretty_print=True):
         super(DerivedType, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         pass
@@ -1416,7 +1426,7 @@ class MyInteger(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyInteger')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyInteger', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1424,7 +1434,7 @@ class MyInteger(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyInteger'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyInteger', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1491,7 +1501,7 @@ class MyBoolean(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyBoolean')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyBoolean', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1499,7 +1509,7 @@ class MyBoolean(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyBoolean'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyBoolean', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1566,7 +1576,7 @@ class MyFloat(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyFloat')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyFloat', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1574,7 +1584,7 @@ class MyFloat(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyFloat'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyFloat', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1641,7 +1651,7 @@ class MyDouble(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyDouble')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyDouble', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1649,7 +1659,7 @@ class MyDouble(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyDouble'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyDouble', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
diff --git a/tests/extensions2_sup.py b/tests/extensions2_sup.py
index 896e1b35477e1e0ebf3ecb72a9943eff3b306fdc..1521f636b115d9d730e0d539d4ab1c2ce1a6f36b 100644
--- a/tests/extensions2_sup.py
+++ b/tests/extensions2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -679,7 +689,7 @@ class SpecialDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='SpecialDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='SpecialDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -687,7 +697,7 @@ class SpecialDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='SpecialDate'):
         if self.SpecialProperty is not None and 'SpecialProperty' not in already_processed:
             already_processed.add('SpecialProperty')
-            outfile.write(' SpecialProperty=%s' % (self.gds_format_string(quote_attrib(self.SpecialProperty).encode(ExternalEncoding), input_name='SpecialProperty'), ))
+            outfile.write(' SpecialProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.SpecialProperty), input_name='SpecialProperty')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='SpecialDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -754,7 +764,7 @@ class ExtremeDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='ExtremeDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='ExtremeDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -762,7 +772,7 @@ class ExtremeDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='ExtremeDate'):
         if self.ExtremeProperty is not None and 'ExtremeProperty' not in already_processed:
             already_processed.add('ExtremeProperty')
-            outfile.write(' ExtremeProperty=%s' % (self.gds_format_string(quote_attrib(self.ExtremeProperty).encode(ExternalEncoding), input_name='ExtremeProperty'), ))
+            outfile.write(' ExtremeProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.ExtremeProperty), input_name='ExtremeProperty')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='ExtremeDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -829,7 +839,7 @@ class singleExtremeDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='singleExtremeDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='singleExtremeDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -837,7 +847,7 @@ class singleExtremeDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='singleExtremeDate'):
         if self.ExtremeProperty is not None and 'ExtremeProperty' not in already_processed:
             already_processed.add('ExtremeProperty')
-            outfile.write(' ExtremeProperty=%s' % (self.gds_format_string(quote_attrib(self.ExtremeProperty).encode(ExternalEncoding), input_name='ExtremeProperty'), ))
+            outfile.write(' ExtremeProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.ExtremeProperty), input_name='ExtremeProperty')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='singleExtremeDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1037,7 +1047,7 @@ class simpleFactoidType(GeneratedsSuper):
             eol_ = ''
         if self.relation is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%srelation>%s</%srelation>%s' % (namespace_, self.gds_format_string(quote_xml(self.relation).encode(ExternalEncoding), input_name='relation'), namespace_, eol_))
+            outfile.write('<%srelation>%s</%srelation>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.relation), input_name='relation')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1235,7 +1245,7 @@ class BaseType(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='BaseType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='BaseType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1243,10 +1253,10 @@ class BaseType(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='BaseType'):
         if self.BaseProperty1 is not None and 'BaseProperty1' not in already_processed:
             already_processed.add('BaseProperty1')
-            outfile.write(' BaseProperty1=%s' % (self.gds_format_string(quote_attrib(self.BaseProperty1).encode(ExternalEncoding), input_name='BaseProperty1'), ))
+            outfile.write(' BaseProperty1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.BaseProperty1), input_name='BaseProperty1')), ))
         if self.BaseProperty2 is not None and 'BaseProperty2' not in already_processed:
             already_processed.add('BaseProperty2')
-            outfile.write(' BaseProperty2=%s' % (self.gds_format_string(quote_attrib(self.BaseProperty2).encode(ExternalEncoding), input_name='BaseProperty2'), ))
+            outfile.write(' BaseProperty2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.BaseProperty2), input_name='BaseProperty2')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1331,7 +1341,7 @@ class DerivedType(BaseType):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='DerivedType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='DerivedType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1340,10 +1350,10 @@ class DerivedType(BaseType):
         super(DerivedType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='DerivedType')
         if self.DerivedProperty1 is not None and 'DerivedProperty1' not in already_processed:
             already_processed.add('DerivedProperty1')
-            outfile.write(' DerivedProperty1=%s' % (self.gds_format_string(quote_attrib(self.DerivedProperty1).encode(ExternalEncoding), input_name='DerivedProperty1'), ))
+            outfile.write(' DerivedProperty1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.DerivedProperty1), input_name='DerivedProperty1')), ))
         if self.DerivedProperty2 is not None and 'DerivedProperty2' not in already_processed:
             already_processed.add('DerivedProperty2')
-            outfile.write(' DerivedProperty2=%s' % (self.gds_format_string(quote_attrib(self.DerivedProperty2).encode(ExternalEncoding), input_name='DerivedProperty2'), ))
+            outfile.write(' DerivedProperty2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.DerivedProperty2), input_name='DerivedProperty2')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='DerivedType', fromsubclass_=False, pretty_print=True):
         super(DerivedType, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         pass
@@ -1416,7 +1426,7 @@ class MyInteger(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyInteger')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyInteger', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1424,7 +1434,7 @@ class MyInteger(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyInteger'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyInteger', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1491,7 +1501,7 @@ class MyBoolean(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyBoolean')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyBoolean', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1499,7 +1509,7 @@ class MyBoolean(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyBoolean'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyBoolean', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1566,7 +1576,7 @@ class MyFloat(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyFloat')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyFloat', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1574,7 +1584,7 @@ class MyFloat(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyFloat'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyFloat', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1641,7 +1651,7 @@ class MyDouble(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='MyDouble')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='MyDouble', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1649,7 +1659,7 @@ class MyDouble(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='MyDouble'):
         if self.MyAttr is not None and 'MyAttr' not in already_processed:
             already_processed.add('MyAttr')
-            outfile.write(' MyAttr=%s' % (self.gds_format_string(quote_attrib(self.MyAttr).encode(ExternalEncoding), input_name='MyAttr'), ))
+            outfile.write(' MyAttr=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.MyAttr), input_name='MyAttr')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='MyDouble', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
diff --git a/tests/mapcleanname1_sup.py b/tests/mapcleanname1_sup.py
index 1903d385d7849233c10cf4bb58840f1bdf294c41..f156ff530f88aca259d8bac3c4df565682ad6632 100644
--- a/tests/mapcleanname1_sup.py
+++ b/tests/mapcleanname1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -710,7 +720,7 @@ class complex_type01(GeneratedsSuper):
             eol_ = ''
         if self.string_value01 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value01>%s</%sstring_value01>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value01).encode(ExternalEncoding), input_name='string_value01'), namespace_, eol_))
+            outfile.write('<%sstring_value01>%s</%sstring_value01>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value01), input_name='string_value01')), namespace_, eol_))
         for integer_value01_ in self.integer_value01:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value01>%s</%sinteger_value01>%s' % (namespace_, self.gds_format_integer(integer_value01_, input_name='integer_value01'), namespace_, eol_))
@@ -836,7 +846,7 @@ class complex_type02(GeneratedsSuper):
             eol_ = ''
         if self.string_value02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value02).encode(ExternalEncoding), input_name='string_value02'), namespace_, eol_))
+            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value02), input_name='string_value02')), namespace_, eol_))
         for integer_value02_ in self.integer_value02:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value02>%s</%sinteger_value02>%s' % (namespace_, self.gds_format_integer(integer_value02_, input_name='integer_value02'), namespace_, eol_))
@@ -954,7 +964,7 @@ class complex_type03(complex_type02):
             eol_ = ''
         if self.string_value03 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value03).encode(ExternalEncoding), input_name='string_value03'), namespace_, eol_))
+            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value03), input_name='string_value03')), namespace_, eol_))
         for integer_value03_ in self.integer_value03:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value03>%s</%sinteger_value03>%s' % (namespace_, self.gds_format_integer(integer_value03_, input_name='integer_value03'), namespace_, eol_))
@@ -1074,7 +1084,7 @@ class type_(GeneratedsSuper):
             eol_ = ''
         if self.string_value02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value02).encode(ExternalEncoding), input_name='string_value02'), namespace_, eol_))
+            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value02), input_name='string_value02')), namespace_, eol_))
         for integer_value02_ in self.integer_value02:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value02>%s</%sinteger_value02>%s' % (namespace_, self.gds_format_integer(integer_value02_, input_name='integer_value02'), namespace_, eol_))
@@ -1192,7 +1202,7 @@ class complex_type04(type_):
             eol_ = ''
         if self.string_value03 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value03).encode(ExternalEncoding), input_name='string_value03'), namespace_, eol_))
+            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value03), input_name='string_value03')), namespace_, eol_))
         for integer_value03_ in self.integer_value03:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value03>%s</%sinteger_value03>%s' % (namespace_, self.gds_format_integer(integer_value03_, input_name='integer_value03'), namespace_, eol_))
@@ -1312,7 +1322,7 @@ class build_(GeneratedsSuper):
             eol_ = ''
         if self.string_value02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value02).encode(ExternalEncoding), input_name='string_value02'), namespace_, eol_))
+            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value02), input_name='string_value02')), namespace_, eol_))
         for integer_value02_ in self.integer_value02:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value02>%s</%sinteger_value02>%s' % (namespace_, self.gds_format_integer(integer_value02_, input_name='integer_value02'), namespace_, eol_))
@@ -1430,7 +1440,7 @@ class complex_type05(build_):
             eol_ = ''
         if self.string_value03 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value03).encode(ExternalEncoding), input_name='string_value03'), namespace_, eol_))
+            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value03), input_name='string_value03')), namespace_, eol_))
         for integer_value03_ in self.integer_value03:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value03>%s</%sinteger_value03>%s' % (namespace_, self.gds_format_integer(integer_value03_, input_name='integer_value03'), namespace_, eol_))
diff --git a/tests/mapcleanname2_sup.py b/tests/mapcleanname2_sup.py
index 1903d385d7849233c10cf4bb58840f1bdf294c41..f156ff530f88aca259d8bac3c4df565682ad6632 100644
--- a/tests/mapcleanname2_sup.py
+++ b/tests/mapcleanname2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -710,7 +720,7 @@ class complex_type01(GeneratedsSuper):
             eol_ = ''
         if self.string_value01 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value01>%s</%sstring_value01>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value01).encode(ExternalEncoding), input_name='string_value01'), namespace_, eol_))
+            outfile.write('<%sstring_value01>%s</%sstring_value01>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value01), input_name='string_value01')), namespace_, eol_))
         for integer_value01_ in self.integer_value01:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value01>%s</%sinteger_value01>%s' % (namespace_, self.gds_format_integer(integer_value01_, input_name='integer_value01'), namespace_, eol_))
@@ -836,7 +846,7 @@ class complex_type02(GeneratedsSuper):
             eol_ = ''
         if self.string_value02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value02).encode(ExternalEncoding), input_name='string_value02'), namespace_, eol_))
+            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value02), input_name='string_value02')), namespace_, eol_))
         for integer_value02_ in self.integer_value02:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value02>%s</%sinteger_value02>%s' % (namespace_, self.gds_format_integer(integer_value02_, input_name='integer_value02'), namespace_, eol_))
@@ -954,7 +964,7 @@ class complex_type03(complex_type02):
             eol_ = ''
         if self.string_value03 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value03).encode(ExternalEncoding), input_name='string_value03'), namespace_, eol_))
+            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value03), input_name='string_value03')), namespace_, eol_))
         for integer_value03_ in self.integer_value03:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value03>%s</%sinteger_value03>%s' % (namespace_, self.gds_format_integer(integer_value03_, input_name='integer_value03'), namespace_, eol_))
@@ -1074,7 +1084,7 @@ class type_(GeneratedsSuper):
             eol_ = ''
         if self.string_value02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value02).encode(ExternalEncoding), input_name='string_value02'), namespace_, eol_))
+            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value02), input_name='string_value02')), namespace_, eol_))
         for integer_value02_ in self.integer_value02:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value02>%s</%sinteger_value02>%s' % (namespace_, self.gds_format_integer(integer_value02_, input_name='integer_value02'), namespace_, eol_))
@@ -1192,7 +1202,7 @@ class complex_type04(type_):
             eol_ = ''
         if self.string_value03 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value03).encode(ExternalEncoding), input_name='string_value03'), namespace_, eol_))
+            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value03), input_name='string_value03')), namespace_, eol_))
         for integer_value03_ in self.integer_value03:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value03>%s</%sinteger_value03>%s' % (namespace_, self.gds_format_integer(integer_value03_, input_name='integer_value03'), namespace_, eol_))
@@ -1312,7 +1322,7 @@ class build_(GeneratedsSuper):
             eol_ = ''
         if self.string_value02 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value02).encode(ExternalEncoding), input_name='string_value02'), namespace_, eol_))
+            outfile.write('<%sstring_value02>%s</%sstring_value02>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value02), input_name='string_value02')), namespace_, eol_))
         for integer_value02_ in self.integer_value02:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value02>%s</%sinteger_value02>%s' % (namespace_, self.gds_format_integer(integer_value02_, input_name='integer_value02'), namespace_, eol_))
@@ -1430,7 +1440,7 @@ class complex_type05(build_):
             eol_ = ''
         if self.string_value03 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_format_string(quote_xml(self.string_value03).encode(ExternalEncoding), input_name='string_value03'), namespace_, eol_))
+            outfile.write('<%sstring_value03>%s</%sstring_value03>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.string_value03), input_name='string_value03')), namespace_, eol_))
         for integer_value03_ in self.integer_value03:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_value03>%s</%sinteger_value03>%s' % (namespace_, self.gds_format_integer(integer_value03_, input_name='integer_value03'), namespace_, eol_))
diff --git a/tests/nested_def1_sup.py b/tests/nested_def1_sup.py
index 901d61a3479a7c909b318c8e11370a90fdde5bb7..a5060b8054ef2614fe189abd690efc7c5301a8ef 100644
--- a/tests/nested_def1_sup.py
+++ b/tests/nested_def1_sup.py
@@ -32,6 +32,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -351,6 +355,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -405,7 +415,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -427,7 +437,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -919,10 +929,10 @@ class inner_001(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='inner_001'):
         if self.attrA1 is not None and 'attrA1' not in already_processed:
             already_processed.add('attrA1')
-            outfile.write(' attrA1=%s' % (self.gds_format_string(quote_attrib(self.attrA1).encode(ExternalEncoding), input_name='attrA1'), ))
+            outfile.write(' attrA1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrA1), input_name='attrA1')), ))
         if self.attrA2 is not None and 'attrA2' not in already_processed:
             already_processed.add('attrA2')
-            outfile.write(' attrA2=%s' % (self.gds_format_string(quote_attrib(self.attrA2).encode(ExternalEncoding), input_name='attrA2'), ))
+            outfile.write(' attrA2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrA2), input_name='attrA2')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='inner_001', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -999,10 +1009,10 @@ class inner_002(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='inner_002'):
         if self.attrB1 is not None and 'attrB1' not in already_processed:
             already_processed.add('attrB1')
-            outfile.write(' attrB1=%s' % (self.gds_format_string(quote_attrib(self.attrB1).encode(ExternalEncoding), input_name='attrB1'), ))
+            outfile.write(' attrB1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrB1), input_name='attrB1')), ))
         if self.attrB2 is not None and 'attrB2' not in already_processed:
             already_processed.add('attrB2')
-            outfile.write(' attrB2=%s' % (self.gds_format_string(quote_attrib(self.attrB2).encode(ExternalEncoding), input_name='attrB2'), ))
+            outfile.write(' attrB2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrB2), input_name='attrB2')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='inner_002', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
diff --git a/tests/nested_def2_sup.py b/tests/nested_def2_sup.py
index 901d61a3479a7c909b318c8e11370a90fdde5bb7..a5060b8054ef2614fe189abd690efc7c5301a8ef 100644
--- a/tests/nested_def2_sup.py
+++ b/tests/nested_def2_sup.py
@@ -32,6 +32,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -351,6 +355,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -405,7 +415,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -427,7 +437,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -919,10 +929,10 @@ class inner_001(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='inner_001'):
         if self.attrA1 is not None and 'attrA1' not in already_processed:
             already_processed.add('attrA1')
-            outfile.write(' attrA1=%s' % (self.gds_format_string(quote_attrib(self.attrA1).encode(ExternalEncoding), input_name='attrA1'), ))
+            outfile.write(' attrA1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrA1), input_name='attrA1')), ))
         if self.attrA2 is not None and 'attrA2' not in already_processed:
             already_processed.add('attrA2')
-            outfile.write(' attrA2=%s' % (self.gds_format_string(quote_attrib(self.attrA2).encode(ExternalEncoding), input_name='attrA2'), ))
+            outfile.write(' attrA2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrA2), input_name='attrA2')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='inner_001', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -999,10 +1009,10 @@ class inner_002(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='inner_002'):
         if self.attrB1 is not None and 'attrB1' not in already_processed:
             already_processed.add('attrB1')
-            outfile.write(' attrB1=%s' % (self.gds_format_string(quote_attrib(self.attrB1).encode(ExternalEncoding), input_name='attrB1'), ))
+            outfile.write(' attrB1=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrB1), input_name='attrB1')), ))
         if self.attrB2 is not None and 'attrB2' not in already_processed:
             already_processed.add('attrB2')
-            outfile.write(' attrB2=%s' % (self.gds_format_string(quote_attrib(self.attrB2).encode(ExternalEncoding), input_name='attrB2'), ))
+            outfile.write(' attrB2=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.attrB2), input_name='attrB2')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='inner_002', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
diff --git a/tests/out1_sup.py b/tests/out1_sup.py
index 6f52bae0c9d5545b04a4d0e291967e75403aea5b..c3ecddf5f82270f512e1f5d01d3f90d41cb4eab5 100644
--- a/tests/out1_sup.py
+++ b/tests/out1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1187,7 +1197,7 @@ class person(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='person'):
         if self.value is not None and 'value' not in already_processed:
             already_processed.add('value')
-            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
+            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), ))
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
             outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
@@ -1196,10 +1206,10 @@ class person(GeneratedsSuper):
             outfile.write(' ratio="%s"' % self.gds_format_float(self.ratio, input_name='ratio'))
         if self.fruit is not None and 'fruit' not in already_processed:
             already_processed.add('fruit')
-            outfile.write(' fruit=%s' % (self.gds_format_string(quote_attrib(self.fruit).encode(ExternalEncoding), input_name='fruit'), ))
+            outfile.write(' fruit=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.fruit), input_name='fruit')), ))
         if self.vegetable is not None and 'vegetable' not in already_processed:
             already_processed.add('vegetable')
-            outfile.write(' vegetable=%s' % (self.gds_format_string(quote_attrib(self.vegetable).encode(ExternalEncoding), input_name='vegetable'), ))
+            outfile.write(' vegetable=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.vegetable), input_name='vegetable')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1211,10 +1221,10 @@ class person(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         for interest_ in self.interest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_format_string(quote_xml(interest_).encode(ExternalEncoding), input_name='interest'), namespace_, eol_))
+            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(interest_), input_name='interest')), namespace_, eol_))
         if self.category is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scategory>%s</%scategory>%s' % (namespace_, self.gds_format_integer(self.category, input_name='category'), namespace_, eol_))
@@ -1224,7 +1234,7 @@ class person(GeneratedsSuper):
             promoter_.export(outfile, level, namespace_, name_='promoter', pretty_print=pretty_print)
         if self.description is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.description).encode(ExternalEncoding), input_name='description'), namespace_, eol_))
+            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.description), input_name='description')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='person'):
         level += 1
         already_processed = set()
@@ -1255,13 +1265,13 @@ class person(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.name is not None:
             showIndent(outfile, level)
-            outfile.write('name=%s,\n' % quote_python(self.name).encode(ExternalEncoding))
+            outfile.write('name=%s,\n' % self.gds_encode(quote_python(self.name)))
         showIndent(outfile, level)
         outfile.write('interest=[\n')
         level += 1
         for interest_ in self.interest:
             showIndent(outfile, level)
-            outfile.write('%s,\n' % quote_python(interest_).encode(ExternalEncoding))
+            outfile.write('%s,\n' % self.gds_encode(quote_python(interest_)))
         level -= 1
         showIndent(outfile, level)
         outfile.write('],\n')
@@ -1294,7 +1304,7 @@ class person(GeneratedsSuper):
         outfile.write('],\n')
         if self.description is not None:
             showIndent(outfile, level)
-            outfile.write('description=%s,\n' % quote_python(self.description).encode(ExternalEncoding))
+            outfile.write('description=%s,\n' % self.gds_encode(quote_python(self.description)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1450,12 +1460,12 @@ class programmer(person):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
         self.eldate = initvalue_
-        if isinstance(eldatetime, basestring):
+        if isinstance(eldatetime, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime
@@ -1569,10 +1579,10 @@ class programmer(person):
         super(programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='programmer')
         if self.language is not None and 'language' not in already_processed:
             already_processed.add('language')
-            outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
+            outfile.write(' language=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.language), input_name='language')), ))
         if self.area is not None and 'area' not in already_processed:
             already_processed.add('area')
-            outfile.write(' area=%s' % (self.gds_format_string(quote_attrib(self.area).encode(ExternalEncoding), input_name='area'), ))
+            outfile.write(' area=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.area), input_name='area')), ))
         if self.attrposint is not None and 'attrposint' not in already_processed:
             already_processed.add('attrposint')
             outfile.write(' attrposint="%s"' % self.gds_format_integer(self.attrposint, input_name='attrposint'))
@@ -1597,7 +1607,7 @@ class programmer(person):
             eol_ = ''
         if self.email is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_format_string(quote_xml(self.email).encode(ExternalEncoding), input_name='email'), namespace_, eol_))
+            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.email), input_name='email')), namespace_, eol_))
         if self.elposint is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selposint>%s</%selposint>%s' % (namespace_, self.gds_format_integer(self.elposint, input_name='elposint'), namespace_, eol_))
@@ -1618,7 +1628,7 @@ class programmer(person):
             outfile.write('<%seldatetime>%s</%seldatetime>%s' % (namespace_, self.gds_format_datetime(self.eldatetime, input_name='eldatetime'), namespace_, eol_))
         if self.eltoken is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_format_string(quote_xml(self.eltoken).encode(ExternalEncoding), input_name='eltoken'), namespace_, eol_))
+            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.eltoken), input_name='eltoken')), namespace_, eol_))
         if self.elshort is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selshort>%s</%selshort>%s' % (namespace_, self.gds_format_integer(self.elshort, input_name='elshort'), namespace_, eol_))
@@ -1629,7 +1639,7 @@ class programmer(person):
             self.elparam.export(outfile, level, namespace_, name_='elparam', pretty_print=pretty_print)
         if self.elarraytypes is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_format_string(quote_xml(self.elarraytypes).encode(ExternalEncoding), input_name='elarraytypes'), namespace_, eol_))
+            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.elarraytypes), input_name='elarraytypes')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='programmer'):
         level += 1
         already_processed = set()
@@ -1666,7 +1676,7 @@ class programmer(person):
         super(programmer, self).exportLiteralChildren(outfile, level, name_)
         if self.email is not None:
             showIndent(outfile, level)
-            outfile.write('email=%s,\n' % quote_python(self.email).encode(ExternalEncoding))
+            outfile.write('email=%s,\n' % self.gds_encode(quote_python(self.email)))
         if self.elposint is not None:
             showIndent(outfile, level)
             outfile.write('elposint=%d,\n' % self.elposint)
@@ -1687,7 +1697,7 @@ class programmer(person):
             outfile.write('eldatetime=model_.GeneratedsSuper.gds_parse_datetime("%s"),\n' % self.gds_format_datetime(self.eldatetime, input_name='eldatetime'))
         if self.eltoken is not None:
             showIndent(outfile, level)
-            outfile.write('eltoken=%s,\n' % quote_python(self.eltoken).encode(ExternalEncoding))
+            outfile.write('eltoken=%s,\n' % self.gds_encode(quote_python(self.eltoken)))
         if self.elshort is not None:
             showIndent(outfile, level)
             outfile.write('elshort=%d,\n' % self.elshort)
@@ -1702,7 +1712,7 @@ class programmer(person):
             outfile.write('),\n')
         if self.elarraytypes is not None:
             showIndent(outfile, level)
-            outfile.write('elarraytypes=%s,\n' % quote_python(self.elarraytypes).encode(ExternalEncoding))
+            outfile.write('elarraytypes=%s,\n' % self.gds_encode(quote_python(self.elarraytypes)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1963,7 +1973,7 @@ class param(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='param')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='param', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1971,7 +1981,7 @@ class param(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='param'):
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
-            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
+            outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), ))
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
             outfile.write(' name=%s' % (quote_attrib(self.name), ))
@@ -1983,10 +1993,10 @@ class param(GeneratedsSuper):
             outfile.write(' flow=%s' % (quote_attrib(self.flow), ))
         if self.semantic is not None and 'semantic' not in already_processed:
             already_processed.add('semantic')
-            outfile.write(' semantic=%s' % (self.gds_format_string(quote_attrib(self.semantic).encode(ExternalEncoding), input_name='semantic'), ))
+            outfile.write(' semantic=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.semantic), input_name='semantic')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
-            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
+            outfile.write(' type=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.type_), input_name='type')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='param', fromsubclass_=False, pretty_print=True):
         pass
     def exportLiteral(self, outfile, level, name_='param'):
@@ -2166,7 +2176,7 @@ class python_programmer(programmer):
         super(python_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='python-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='python-programmer', fromsubclass_=False, pretty_print=True):
         super(python_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2175,7 +2185,7 @@ class python_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='python-programmer'):
         level += 1
         already_processed = set()
@@ -2192,7 +2202,7 @@ class python_programmer(programmer):
         super(python_programmer, self).exportLiteralChildren(outfile, level, name_)
         if self.favorite_editor is not None:
             showIndent(outfile, level)
-            outfile.write('favorite_editor=%s,\n' % quote_python(self.favorite_editor).encode(ExternalEncoding))
+            outfile.write('favorite_editor=%s,\n' % self.gds_encode(quote_python(self.favorite_editor)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2322,10 +2332,10 @@ class java_programmer(programmer):
         super(java_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='java-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
         if self.status is not None and 'status' not in already_processed:
             already_processed.add('status')
-            outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), ))
+            outfile.write(' status=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.status), input_name='status')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='java-programmer', fromsubclass_=False, pretty_print=True):
         super(java_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2334,7 +2344,7 @@ class java_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='java-programmer'):
         level += 1
         already_processed = set()
@@ -2355,7 +2365,7 @@ class java_programmer(programmer):
         super(java_programmer, self).exportLiteralChildren(outfile, level, name_)
         if self.favorite_editor is not None:
             showIndent(outfile, level)
-            outfile.write('favorite_editor=%s,\n' % quote_python(self.favorite_editor).encode(ExternalEncoding))
+            outfile.write('favorite_editor=%s,\n' % self.gds_encode(quote_python(self.favorite_editor)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2499,10 +2509,10 @@ class agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -2519,10 +2529,10 @@ class agent(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.firstname is not None:
             showIndent(outfile, level)
-            outfile.write('firstname=%s,\n' % quote_python(self.firstname).encode(ExternalEncoding))
+            outfile.write('firstname=%s,\n' % self.gds_encode(quote_python(self.firstname)))
         if self.lastname is not None:
             showIndent(outfile, level)
-            outfile.write('lastname=%s,\n' % quote_python(self.lastname).encode(ExternalEncoding))
+            outfile.write('lastname=%s,\n' % self.gds_encode(quote_python(self.lastname)))
         if self.priority is not None:
             showIndent(outfile, level)
             outfile.write('priority=%f,\n' % self.priority)
@@ -2683,10 +2693,10 @@ class special_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -2703,10 +2713,10 @@ class special_agent(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.firstname is not None:
             showIndent(outfile, level)
-            outfile.write('firstname=%s,\n' % quote_python(self.firstname).encode(ExternalEncoding))
+            outfile.write('firstname=%s,\n' % self.gds_encode(quote_python(self.firstname)))
         if self.lastname is not None:
             showIndent(outfile, level)
-            outfile.write('lastname=%s,\n' % quote_python(self.lastname).encode(ExternalEncoding))
+            outfile.write('lastname=%s,\n' % self.gds_encode(quote_python(self.lastname)))
         if self.priority is not None:
             showIndent(outfile, level)
             outfile.write('priority=%f,\n' % self.priority)
@@ -2900,10 +2910,10 @@ class booster(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.other_name is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sother-name>%s</%sother-name>%s' % (namespace_, self.gds_format_float(self.other_name, input_name='other-name'), namespace_, eol_))
@@ -2929,10 +2939,10 @@ class booster(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.firstname is not None:
             showIndent(outfile, level)
-            outfile.write('firstname=%s,\n' % quote_python(self.firstname).encode(ExternalEncoding))
+            outfile.write('firstname=%s,\n' % self.gds_encode(quote_python(self.firstname)))
         if self.lastname is not None:
             showIndent(outfile, level)
-            outfile.write('lastname=%s,\n' % quote_python(self.lastname).encode(ExternalEncoding))
+            outfile.write('lastname=%s,\n' % self.gds_encode(quote_python(self.lastname)))
         if self.other_name is not None:
             showIndent(outfile, level)
             outfile.write('other_name=%f,\n' % self.other_name)
@@ -3130,7 +3140,7 @@ class info(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='info'):
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
-            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
+            outfile.write(' name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.name), input_name='name')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
             outfile.write(' type="%s"' % self.gds_format_integer(self.type_, input_name='type'))
@@ -3298,7 +3308,7 @@ class client_handlerType(GeneratedsSuper):
             eol_ = ''
         if self.fullname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fullname).encode(ExternalEncoding), input_name='fullname'), namespace_, eol_))
+            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fullname), input_name='fullname')), namespace_, eol_))
         if self.refid is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srefid>%s</%srefid>%s' % (namespace_, self.gds_format_integer(self.refid, input_name='refid'), namespace_, eol_))
@@ -3313,7 +3323,7 @@ class client_handlerType(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.fullname is not None:
             showIndent(outfile, level)
-            outfile.write('fullname=%s,\n' % quote_python(self.fullname).encode(ExternalEncoding))
+            outfile.write('fullname=%s,\n' % self.gds_encode(quote_python(self.fullname)))
         if self.refid is not None:
             showIndent(outfile, level)
             outfile.write('refid=%d,\n' % self.refid)
diff --git a/tests/out2_sup.py b/tests/out2_sup.py
index 6f52bae0c9d5545b04a4d0e291967e75403aea5b..c3ecddf5f82270f512e1f5d01d3f90d41cb4eab5 100644
--- a/tests/out2_sup.py
+++ b/tests/out2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1187,7 +1197,7 @@ class person(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='person'):
         if self.value is not None and 'value' not in already_processed:
             already_processed.add('value')
-            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
+            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), ))
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
             outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
@@ -1196,10 +1206,10 @@ class person(GeneratedsSuper):
             outfile.write(' ratio="%s"' % self.gds_format_float(self.ratio, input_name='ratio'))
         if self.fruit is not None and 'fruit' not in already_processed:
             already_processed.add('fruit')
-            outfile.write(' fruit=%s' % (self.gds_format_string(quote_attrib(self.fruit).encode(ExternalEncoding), input_name='fruit'), ))
+            outfile.write(' fruit=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.fruit), input_name='fruit')), ))
         if self.vegetable is not None and 'vegetable' not in already_processed:
             already_processed.add('vegetable')
-            outfile.write(' vegetable=%s' % (self.gds_format_string(quote_attrib(self.vegetable).encode(ExternalEncoding), input_name='vegetable'), ))
+            outfile.write(' vegetable=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.vegetable), input_name='vegetable')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1211,10 +1221,10 @@ class person(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         for interest_ in self.interest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_format_string(quote_xml(interest_).encode(ExternalEncoding), input_name='interest'), namespace_, eol_))
+            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(interest_), input_name='interest')), namespace_, eol_))
         if self.category is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scategory>%s</%scategory>%s' % (namespace_, self.gds_format_integer(self.category, input_name='category'), namespace_, eol_))
@@ -1224,7 +1234,7 @@ class person(GeneratedsSuper):
             promoter_.export(outfile, level, namespace_, name_='promoter', pretty_print=pretty_print)
         if self.description is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.description).encode(ExternalEncoding), input_name='description'), namespace_, eol_))
+            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.description), input_name='description')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='person'):
         level += 1
         already_processed = set()
@@ -1255,13 +1265,13 @@ class person(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.name is not None:
             showIndent(outfile, level)
-            outfile.write('name=%s,\n' % quote_python(self.name).encode(ExternalEncoding))
+            outfile.write('name=%s,\n' % self.gds_encode(quote_python(self.name)))
         showIndent(outfile, level)
         outfile.write('interest=[\n')
         level += 1
         for interest_ in self.interest:
             showIndent(outfile, level)
-            outfile.write('%s,\n' % quote_python(interest_).encode(ExternalEncoding))
+            outfile.write('%s,\n' % self.gds_encode(quote_python(interest_)))
         level -= 1
         showIndent(outfile, level)
         outfile.write('],\n')
@@ -1294,7 +1304,7 @@ class person(GeneratedsSuper):
         outfile.write('],\n')
         if self.description is not None:
             showIndent(outfile, level)
-            outfile.write('description=%s,\n' % quote_python(self.description).encode(ExternalEncoding))
+            outfile.write('description=%s,\n' % self.gds_encode(quote_python(self.description)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1450,12 +1460,12 @@ class programmer(person):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
         self.eldate = initvalue_
-        if isinstance(eldatetime, basestring):
+        if isinstance(eldatetime, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime
@@ -1569,10 +1579,10 @@ class programmer(person):
         super(programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='programmer')
         if self.language is not None and 'language' not in already_processed:
             already_processed.add('language')
-            outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
+            outfile.write(' language=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.language), input_name='language')), ))
         if self.area is not None and 'area' not in already_processed:
             already_processed.add('area')
-            outfile.write(' area=%s' % (self.gds_format_string(quote_attrib(self.area).encode(ExternalEncoding), input_name='area'), ))
+            outfile.write(' area=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.area), input_name='area')), ))
         if self.attrposint is not None and 'attrposint' not in already_processed:
             already_processed.add('attrposint')
             outfile.write(' attrposint="%s"' % self.gds_format_integer(self.attrposint, input_name='attrposint'))
@@ -1597,7 +1607,7 @@ class programmer(person):
             eol_ = ''
         if self.email is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_format_string(quote_xml(self.email).encode(ExternalEncoding), input_name='email'), namespace_, eol_))
+            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.email), input_name='email')), namespace_, eol_))
         if self.elposint is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selposint>%s</%selposint>%s' % (namespace_, self.gds_format_integer(self.elposint, input_name='elposint'), namespace_, eol_))
@@ -1618,7 +1628,7 @@ class programmer(person):
             outfile.write('<%seldatetime>%s</%seldatetime>%s' % (namespace_, self.gds_format_datetime(self.eldatetime, input_name='eldatetime'), namespace_, eol_))
         if self.eltoken is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_format_string(quote_xml(self.eltoken).encode(ExternalEncoding), input_name='eltoken'), namespace_, eol_))
+            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.eltoken), input_name='eltoken')), namespace_, eol_))
         if self.elshort is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selshort>%s</%selshort>%s' % (namespace_, self.gds_format_integer(self.elshort, input_name='elshort'), namespace_, eol_))
@@ -1629,7 +1639,7 @@ class programmer(person):
             self.elparam.export(outfile, level, namespace_, name_='elparam', pretty_print=pretty_print)
         if self.elarraytypes is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_format_string(quote_xml(self.elarraytypes).encode(ExternalEncoding), input_name='elarraytypes'), namespace_, eol_))
+            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.elarraytypes), input_name='elarraytypes')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='programmer'):
         level += 1
         already_processed = set()
@@ -1666,7 +1676,7 @@ class programmer(person):
         super(programmer, self).exportLiteralChildren(outfile, level, name_)
         if self.email is not None:
             showIndent(outfile, level)
-            outfile.write('email=%s,\n' % quote_python(self.email).encode(ExternalEncoding))
+            outfile.write('email=%s,\n' % self.gds_encode(quote_python(self.email)))
         if self.elposint is not None:
             showIndent(outfile, level)
             outfile.write('elposint=%d,\n' % self.elposint)
@@ -1687,7 +1697,7 @@ class programmer(person):
             outfile.write('eldatetime=model_.GeneratedsSuper.gds_parse_datetime("%s"),\n' % self.gds_format_datetime(self.eldatetime, input_name='eldatetime'))
         if self.eltoken is not None:
             showIndent(outfile, level)
-            outfile.write('eltoken=%s,\n' % quote_python(self.eltoken).encode(ExternalEncoding))
+            outfile.write('eltoken=%s,\n' % self.gds_encode(quote_python(self.eltoken)))
         if self.elshort is not None:
             showIndent(outfile, level)
             outfile.write('elshort=%d,\n' % self.elshort)
@@ -1702,7 +1712,7 @@ class programmer(person):
             outfile.write('),\n')
         if self.elarraytypes is not None:
             showIndent(outfile, level)
-            outfile.write('elarraytypes=%s,\n' % quote_python(self.elarraytypes).encode(ExternalEncoding))
+            outfile.write('elarraytypes=%s,\n' % self.gds_encode(quote_python(self.elarraytypes)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1963,7 +1973,7 @@ class param(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='param')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='param', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1971,7 +1981,7 @@ class param(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='param'):
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
-            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
+            outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), ))
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
             outfile.write(' name=%s' % (quote_attrib(self.name), ))
@@ -1983,10 +1993,10 @@ class param(GeneratedsSuper):
             outfile.write(' flow=%s' % (quote_attrib(self.flow), ))
         if self.semantic is not None and 'semantic' not in already_processed:
             already_processed.add('semantic')
-            outfile.write(' semantic=%s' % (self.gds_format_string(quote_attrib(self.semantic).encode(ExternalEncoding), input_name='semantic'), ))
+            outfile.write(' semantic=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.semantic), input_name='semantic')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
-            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
+            outfile.write(' type=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.type_), input_name='type')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='param', fromsubclass_=False, pretty_print=True):
         pass
     def exportLiteral(self, outfile, level, name_='param'):
@@ -2166,7 +2176,7 @@ class python_programmer(programmer):
         super(python_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='python-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='python-programmer', fromsubclass_=False, pretty_print=True):
         super(python_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2175,7 +2185,7 @@ class python_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='python-programmer'):
         level += 1
         already_processed = set()
@@ -2192,7 +2202,7 @@ class python_programmer(programmer):
         super(python_programmer, self).exportLiteralChildren(outfile, level, name_)
         if self.favorite_editor is not None:
             showIndent(outfile, level)
-            outfile.write('favorite_editor=%s,\n' % quote_python(self.favorite_editor).encode(ExternalEncoding))
+            outfile.write('favorite_editor=%s,\n' % self.gds_encode(quote_python(self.favorite_editor)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2322,10 +2332,10 @@ class java_programmer(programmer):
         super(java_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='java-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
         if self.status is not None and 'status' not in already_processed:
             already_processed.add('status')
-            outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), ))
+            outfile.write(' status=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.status), input_name='status')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='java-programmer', fromsubclass_=False, pretty_print=True):
         super(java_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2334,7 +2344,7 @@ class java_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def exportLiteral(self, outfile, level, name_='java-programmer'):
         level += 1
         already_processed = set()
@@ -2355,7 +2365,7 @@ class java_programmer(programmer):
         super(java_programmer, self).exportLiteralChildren(outfile, level, name_)
         if self.favorite_editor is not None:
             showIndent(outfile, level)
-            outfile.write('favorite_editor=%s,\n' % quote_python(self.favorite_editor).encode(ExternalEncoding))
+            outfile.write('favorite_editor=%s,\n' % self.gds_encode(quote_python(self.favorite_editor)))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2499,10 +2509,10 @@ class agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -2519,10 +2529,10 @@ class agent(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.firstname is not None:
             showIndent(outfile, level)
-            outfile.write('firstname=%s,\n' % quote_python(self.firstname).encode(ExternalEncoding))
+            outfile.write('firstname=%s,\n' % self.gds_encode(quote_python(self.firstname)))
         if self.lastname is not None:
             showIndent(outfile, level)
-            outfile.write('lastname=%s,\n' % quote_python(self.lastname).encode(ExternalEncoding))
+            outfile.write('lastname=%s,\n' % self.gds_encode(quote_python(self.lastname)))
         if self.priority is not None:
             showIndent(outfile, level)
             outfile.write('priority=%f,\n' % self.priority)
@@ -2683,10 +2693,10 @@ class special_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -2703,10 +2713,10 @@ class special_agent(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.firstname is not None:
             showIndent(outfile, level)
-            outfile.write('firstname=%s,\n' % quote_python(self.firstname).encode(ExternalEncoding))
+            outfile.write('firstname=%s,\n' % self.gds_encode(quote_python(self.firstname)))
         if self.lastname is not None:
             showIndent(outfile, level)
-            outfile.write('lastname=%s,\n' % quote_python(self.lastname).encode(ExternalEncoding))
+            outfile.write('lastname=%s,\n' % self.gds_encode(quote_python(self.lastname)))
         if self.priority is not None:
             showIndent(outfile, level)
             outfile.write('priority=%f,\n' % self.priority)
@@ -2900,10 +2910,10 @@ class booster(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.other_name is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sother-name>%s</%sother-name>%s' % (namespace_, self.gds_format_float(self.other_name, input_name='other-name'), namespace_, eol_))
@@ -2929,10 +2939,10 @@ class booster(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.firstname is not None:
             showIndent(outfile, level)
-            outfile.write('firstname=%s,\n' % quote_python(self.firstname).encode(ExternalEncoding))
+            outfile.write('firstname=%s,\n' % self.gds_encode(quote_python(self.firstname)))
         if self.lastname is not None:
             showIndent(outfile, level)
-            outfile.write('lastname=%s,\n' % quote_python(self.lastname).encode(ExternalEncoding))
+            outfile.write('lastname=%s,\n' % self.gds_encode(quote_python(self.lastname)))
         if self.other_name is not None:
             showIndent(outfile, level)
             outfile.write('other_name=%f,\n' % self.other_name)
@@ -3130,7 +3140,7 @@ class info(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='info'):
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
-            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
+            outfile.write(' name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.name), input_name='name')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
             outfile.write(' type="%s"' % self.gds_format_integer(self.type_, input_name='type'))
@@ -3298,7 +3308,7 @@ class client_handlerType(GeneratedsSuper):
             eol_ = ''
         if self.fullname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fullname).encode(ExternalEncoding), input_name='fullname'), namespace_, eol_))
+            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fullname), input_name='fullname')), namespace_, eol_))
         if self.refid is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srefid>%s</%srefid>%s' % (namespace_, self.gds_format_integer(self.refid, input_name='refid'), namespace_, eol_))
@@ -3313,7 +3323,7 @@ class client_handlerType(GeneratedsSuper):
     def exportLiteralChildren(self, outfile, level, name_):
         if self.fullname is not None:
             showIndent(outfile, level)
-            outfile.write('fullname=%s,\n' % quote_python(self.fullname).encode(ExternalEncoding))
+            outfile.write('fullname=%s,\n' % self.gds_encode(quote_python(self.fullname)))
         if self.refid is not None:
             showIndent(outfile, level)
             outfile.write('refid=%d,\n' % self.refid)
diff --git a/tests/people_procincl1_sup.py b/tests/people_procincl1_sup.py
index c07c2f47b2d950c51b07a82ebc170ebc17fd1e20..979c5509de116c741a3ea6813d443f433308aff8 100644
--- a/tests/people_procincl1_sup.py
+++ b/tests/people_procincl1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1041,7 +1051,7 @@ class person(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='person'):
         if self.value is not None and 'value' not in already_processed:
             already_processed.add('value')
-            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
+            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), ))
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
             outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
@@ -1050,10 +1060,10 @@ class person(GeneratedsSuper):
             outfile.write(' ratio="%s"' % self.gds_format_float(self.ratio, input_name='ratio'))
         if self.fruit is not None and 'fruit' not in already_processed:
             already_processed.add('fruit')
-            outfile.write(' fruit=%s' % (self.gds_format_string(quote_attrib(self.fruit).encode(ExternalEncoding), input_name='fruit'), ))
+            outfile.write(' fruit=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.fruit), input_name='fruit')), ))
         if self.vegetable is not None and 'vegetable' not in already_processed:
             already_processed.add('vegetable')
-            outfile.write(' vegetable=%s' % (self.gds_format_string(quote_attrib(self.vegetable).encode(ExternalEncoding), input_name='vegetable'), ))
+            outfile.write(' vegetable=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.vegetable), input_name='vegetable')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1065,10 +1075,10 @@ class person(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         for interest_ in self.interest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_format_string(quote_xml(interest_).encode(ExternalEncoding), input_name='interest'), namespace_, eol_))
+            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(interest_), input_name='interest')), namespace_, eol_))
         if self.category is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scategory>%s</%scategory>%s' % (namespace_, self.gds_format_integer(self.category, input_name='category'), namespace_, eol_))
@@ -1078,7 +1088,7 @@ class person(GeneratedsSuper):
             promoter_.export(outfile, level, namespace_, name_='promoter', pretty_print=pretty_print)
         if self.description is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.description).encode(ExternalEncoding), input_name='description'), namespace_, eol_))
+            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.description), input_name='description')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1282,7 +1292,7 @@ class param(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='param')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='param', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1290,7 +1300,7 @@ class param(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='param'):
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
-            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
+            outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), ))
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
             outfile.write(' name=%s' % (quote_attrib(self.name), ))
@@ -1302,10 +1312,10 @@ class param(GeneratedsSuper):
             outfile.write(' flow=%s' % (quote_attrib(self.flow), ))
         if self.semantic is not None and 'semantic' not in already_processed:
             already_processed.add('semantic')
-            outfile.write(' semantic=%s' % (self.gds_format_string(quote_attrib(self.semantic).encode(ExternalEncoding), input_name='semantic'), ))
+            outfile.write(' semantic=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.semantic), input_name='semantic')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
-            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
+            outfile.write(' type=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.type_), input_name='type')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='param', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1429,10 +1439,10 @@ class agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -1566,10 +1576,10 @@ class special_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -1711,7 +1721,7 @@ class booster(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='booster'):
         if self.member_id is not None and 'member_id' not in already_processed:
             already_processed.add('member_id')
-            outfile.write(' member-id=%s' % (self.gds_format_string(quote_attrib(self.member_id).encode(ExternalEncoding), input_name='member-id'), ))
+            outfile.write(' member-id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.member_id), input_name='member-id')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='booster', fromsubclass_=False, pretty_print=True):
         if pretty_print:
             eol_ = '\n'
@@ -1719,10 +1729,10 @@ class booster(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.other_name is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sother-name>%s</%sother-name>%s' % (namespace_, self.gds_format_float(self.other_name, input_name='other-name'), namespace_, eol_))
@@ -1855,7 +1865,7 @@ class info(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='info'):
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
-            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
+            outfile.write(' name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.name), input_name='name')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
             outfile.write(' type="%s"' % self.gds_format_integer(self.type_, input_name='type'))
@@ -2042,7 +2052,7 @@ class automobile(vehicle):
             eol_ = ''
         if self.drivername is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdrivername>%s</%sdrivername>%s' % (namespace_, self.gds_format_string(quote_xml(self.drivername).encode(ExternalEncoding), input_name='drivername'), namespace_, eol_))
+            outfile.write('<%sdrivername>%s</%sdrivername>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.drivername), input_name='drivername')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2120,7 +2130,7 @@ class airplane(vehicle):
             eol_ = ''
         if self.pilotname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%spilotname>%s</%spilotname>%s' % (namespace_, self.gds_format_string(quote_xml(self.pilotname).encode(ExternalEncoding), input_name='pilotname'), namespace_, eol_))
+            outfile.write('<%spilotname>%s</%spilotname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.pilotname), input_name='pilotname')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2177,7 +2187,7 @@ class programmer(person):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
@@ -2288,10 +2298,10 @@ class programmer(person):
         super(programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='programmer')
         if self.language is not None and 'language' not in already_processed:
             already_processed.add('language')
-            outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
+            outfile.write(' language=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.language), input_name='language')), ))
         if self.area is not None and 'area' not in already_processed:
             already_processed.add('area')
-            outfile.write(' area=%s' % (self.gds_format_string(quote_attrib(self.area).encode(ExternalEncoding), input_name='area'), ))
+            outfile.write(' area=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.area), input_name='area')), ))
         if self.attrposint is not None and 'attrposint' not in already_processed:
             already_processed.add('attrposint')
             outfile.write(' attrposint="%s"' % self.gds_format_integer(self.attrposint, input_name='attrposint'))
@@ -2316,7 +2326,7 @@ class programmer(person):
             eol_ = ''
         if self.email is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_format_string(quote_xml(self.email).encode(ExternalEncoding), input_name='email'), namespace_, eol_))
+            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.email), input_name='email')), namespace_, eol_))
         if self.elposint is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selposint>%s</%selposint>%s' % (namespace_, self.gds_format_integer(self.elposint, input_name='elposint'), namespace_, eol_))
@@ -2334,7 +2344,7 @@ class programmer(person):
             outfile.write('<%seldate>%s</%seldate>%s' % (namespace_, self.gds_format_date(self.eldate, input_name='eldate'), namespace_, eol_))
         if self.eltoken is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_format_string(quote_xml(self.eltoken).encode(ExternalEncoding), input_name='eltoken'), namespace_, eol_))
+            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.eltoken), input_name='eltoken')), namespace_, eol_))
         if self.elshort is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selshort>%s</%selshort>%s' % (namespace_, self.gds_format_integer(self.elshort, input_name='elshort'), namespace_, eol_))
@@ -2345,7 +2355,7 @@ class programmer(person):
             self.elparam.export(outfile, level, namespace_, name_='elparam', pretty_print=pretty_print)
         if self.elarraytypes is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_format_string(quote_xml(self.elarraytypes).encode(ExternalEncoding), input_name='elarraytypes'), namespace_, eol_))
+            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.elarraytypes), input_name='elarraytypes')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2549,7 +2559,7 @@ class client_handlerType(GeneratedsSuper):
             eol_ = ''
         if self.fullname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fullname).encode(ExternalEncoding), input_name='fullname'), namespace_, eol_))
+            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fullname), input_name='fullname')), namespace_, eol_))
         if self.refid is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srefid>%s</%srefid>%s' % (namespace_, self.gds_format_integer(self.refid, input_name='refid'), namespace_, eol_))
@@ -2642,10 +2652,10 @@ class java_programmer(programmer):
         super(java_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='java-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
         if self.status is not None and 'status' not in already_processed:
             already_processed.add('status')
-            outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), ))
+            outfile.write(' status=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.status), input_name='status')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='java-programmer', fromsubclass_=False, pretty_print=True):
         super(java_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2654,7 +2664,7 @@ class java_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2740,7 +2750,7 @@ class python_programmer(programmer):
         super(python_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='python-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='python-programmer', fromsubclass_=False, pretty_print=True):
         super(python_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2749,7 +2759,7 @@ class python_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/people_procincl2_sup.py b/tests/people_procincl2_sup.py
index c07c2f47b2d950c51b07a82ebc170ebc17fd1e20..979c5509de116c741a3ea6813d443f433308aff8 100644
--- a/tests/people_procincl2_sup.py
+++ b/tests/people_procincl2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1041,7 +1051,7 @@ class person(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='person'):
         if self.value is not None and 'value' not in already_processed:
             already_processed.add('value')
-            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
+            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), ))
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
             outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
@@ -1050,10 +1060,10 @@ class person(GeneratedsSuper):
             outfile.write(' ratio="%s"' % self.gds_format_float(self.ratio, input_name='ratio'))
         if self.fruit is not None and 'fruit' not in already_processed:
             already_processed.add('fruit')
-            outfile.write(' fruit=%s' % (self.gds_format_string(quote_attrib(self.fruit).encode(ExternalEncoding), input_name='fruit'), ))
+            outfile.write(' fruit=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.fruit), input_name='fruit')), ))
         if self.vegetable is not None and 'vegetable' not in already_processed:
             already_processed.add('vegetable')
-            outfile.write(' vegetable=%s' % (self.gds_format_string(quote_attrib(self.vegetable).encode(ExternalEncoding), input_name='vegetable'), ))
+            outfile.write(' vegetable=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.vegetable), input_name='vegetable')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1065,10 +1075,10 @@ class person(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         for interest_ in self.interest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_format_string(quote_xml(interest_).encode(ExternalEncoding), input_name='interest'), namespace_, eol_))
+            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(interest_), input_name='interest')), namespace_, eol_))
         if self.category is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scategory>%s</%scategory>%s' % (namespace_, self.gds_format_integer(self.category, input_name='category'), namespace_, eol_))
@@ -1078,7 +1088,7 @@ class person(GeneratedsSuper):
             promoter_.export(outfile, level, namespace_, name_='promoter', pretty_print=pretty_print)
         if self.description is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.description).encode(ExternalEncoding), input_name='description'), namespace_, eol_))
+            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.description), input_name='description')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1282,7 +1292,7 @@ class param(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='param')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='param', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1290,7 +1300,7 @@ class param(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='param'):
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
-            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
+            outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), ))
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
             outfile.write(' name=%s' % (quote_attrib(self.name), ))
@@ -1302,10 +1312,10 @@ class param(GeneratedsSuper):
             outfile.write(' flow=%s' % (quote_attrib(self.flow), ))
         if self.semantic is not None and 'semantic' not in already_processed:
             already_processed.add('semantic')
-            outfile.write(' semantic=%s' % (self.gds_format_string(quote_attrib(self.semantic).encode(ExternalEncoding), input_name='semantic'), ))
+            outfile.write(' semantic=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.semantic), input_name='semantic')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
-            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
+            outfile.write(' type=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.type_), input_name='type')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='param', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1429,10 +1439,10 @@ class agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -1566,10 +1576,10 @@ class special_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -1711,7 +1721,7 @@ class booster(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='booster'):
         if self.member_id is not None and 'member_id' not in already_processed:
             already_processed.add('member_id')
-            outfile.write(' member-id=%s' % (self.gds_format_string(quote_attrib(self.member_id).encode(ExternalEncoding), input_name='member-id'), ))
+            outfile.write(' member-id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.member_id), input_name='member-id')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='booster', fromsubclass_=False, pretty_print=True):
         if pretty_print:
             eol_ = '\n'
@@ -1719,10 +1729,10 @@ class booster(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.other_name is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sother-name>%s</%sother-name>%s' % (namespace_, self.gds_format_float(self.other_name, input_name='other-name'), namespace_, eol_))
@@ -1855,7 +1865,7 @@ class info(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='info'):
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
-            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
+            outfile.write(' name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.name), input_name='name')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
             outfile.write(' type="%s"' % self.gds_format_integer(self.type_, input_name='type'))
@@ -2042,7 +2052,7 @@ class automobile(vehicle):
             eol_ = ''
         if self.drivername is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdrivername>%s</%sdrivername>%s' % (namespace_, self.gds_format_string(quote_xml(self.drivername).encode(ExternalEncoding), input_name='drivername'), namespace_, eol_))
+            outfile.write('<%sdrivername>%s</%sdrivername>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.drivername), input_name='drivername')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2120,7 +2130,7 @@ class airplane(vehicle):
             eol_ = ''
         if self.pilotname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%spilotname>%s</%spilotname>%s' % (namespace_, self.gds_format_string(quote_xml(self.pilotname).encode(ExternalEncoding), input_name='pilotname'), namespace_, eol_))
+            outfile.write('<%spilotname>%s</%spilotname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.pilotname), input_name='pilotname')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2177,7 +2187,7 @@ class programmer(person):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
@@ -2288,10 +2298,10 @@ class programmer(person):
         super(programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='programmer')
         if self.language is not None and 'language' not in already_processed:
             already_processed.add('language')
-            outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
+            outfile.write(' language=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.language), input_name='language')), ))
         if self.area is not None and 'area' not in already_processed:
             already_processed.add('area')
-            outfile.write(' area=%s' % (self.gds_format_string(quote_attrib(self.area).encode(ExternalEncoding), input_name='area'), ))
+            outfile.write(' area=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.area), input_name='area')), ))
         if self.attrposint is not None and 'attrposint' not in already_processed:
             already_processed.add('attrposint')
             outfile.write(' attrposint="%s"' % self.gds_format_integer(self.attrposint, input_name='attrposint'))
@@ -2316,7 +2326,7 @@ class programmer(person):
             eol_ = ''
         if self.email is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_format_string(quote_xml(self.email).encode(ExternalEncoding), input_name='email'), namespace_, eol_))
+            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.email), input_name='email')), namespace_, eol_))
         if self.elposint is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selposint>%s</%selposint>%s' % (namespace_, self.gds_format_integer(self.elposint, input_name='elposint'), namespace_, eol_))
@@ -2334,7 +2344,7 @@ class programmer(person):
             outfile.write('<%seldate>%s</%seldate>%s' % (namespace_, self.gds_format_date(self.eldate, input_name='eldate'), namespace_, eol_))
         if self.eltoken is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_format_string(quote_xml(self.eltoken).encode(ExternalEncoding), input_name='eltoken'), namespace_, eol_))
+            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.eltoken), input_name='eltoken')), namespace_, eol_))
         if self.elshort is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selshort>%s</%selshort>%s' % (namespace_, self.gds_format_integer(self.elshort, input_name='elshort'), namespace_, eol_))
@@ -2345,7 +2355,7 @@ class programmer(person):
             self.elparam.export(outfile, level, namespace_, name_='elparam', pretty_print=pretty_print)
         if self.elarraytypes is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_format_string(quote_xml(self.elarraytypes).encode(ExternalEncoding), input_name='elarraytypes'), namespace_, eol_))
+            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.elarraytypes), input_name='elarraytypes')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2549,7 +2559,7 @@ class client_handlerType(GeneratedsSuper):
             eol_ = ''
         if self.fullname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fullname).encode(ExternalEncoding), input_name='fullname'), namespace_, eol_))
+            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fullname), input_name='fullname')), namespace_, eol_))
         if self.refid is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srefid>%s</%srefid>%s' % (namespace_, self.gds_format_integer(self.refid, input_name='refid'), namespace_, eol_))
@@ -2642,10 +2652,10 @@ class java_programmer(programmer):
         super(java_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='java-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
         if self.status is not None and 'status' not in already_processed:
             already_processed.add('status')
-            outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), ))
+            outfile.write(' status=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.status), input_name='status')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='java-programmer', fromsubclass_=False, pretty_print=True):
         super(java_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2654,7 +2664,7 @@ class java_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -2740,7 +2750,7 @@ class python_programmer(programmer):
         super(python_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='python-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='python-programmer', fromsubclass_=False, pretty_print=True):
         super(python_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -2749,7 +2759,7 @@ class python_programmer(programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/prefix_classname1_sup.py b/tests/prefix_classname1_sup.py
index d607f862e4a5437bcc41c256cf1686d8c7d4d814..8c09004309e71444a7fb66313c58160d55b578d6 100644
--- a/tests/prefix_classname1_sup.py
+++ b/tests/prefix_classname1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1003,7 +1013,7 @@ class tomato_person(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='person'):
         if self.value is not None and 'value' not in already_processed:
             already_processed.add('value')
-            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
+            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), ))
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
             outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
@@ -1012,10 +1022,10 @@ class tomato_person(GeneratedsSuper):
             outfile.write(' ratio="%s"' % self.gds_format_float(self.ratio, input_name='ratio'))
         if self.fruit is not None and 'fruit' not in already_processed:
             already_processed.add('fruit')
-            outfile.write(' fruit=%s' % (self.gds_format_string(quote_attrib(self.fruit).encode(ExternalEncoding), input_name='fruit'), ))
+            outfile.write(' fruit=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.fruit), input_name='fruit')), ))
         if self.vegetable is not None and 'vegetable' not in already_processed:
             already_processed.add('vegetable')
-            outfile.write(' vegetable=%s' % (self.gds_format_string(quote_attrib(self.vegetable).encode(ExternalEncoding), input_name='vegetable'), ))
+            outfile.write(' vegetable=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.vegetable), input_name='vegetable')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1027,10 +1037,10 @@ class tomato_person(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         for interest_ in self.interest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_format_string(quote_xml(interest_).encode(ExternalEncoding), input_name='interest'), namespace_, eol_))
+            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(interest_), input_name='interest')), namespace_, eol_))
         if self.category is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scategory>%s</%scategory>%s' % (namespace_, self.gds_format_integer(self.category, input_name='category'), namespace_, eol_))
@@ -1040,7 +1050,7 @@ class tomato_person(GeneratedsSuper):
             promoter_.export(outfile, level, namespace_, name_='promoter', pretty_print=pretty_print)
         if self.description is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.description).encode(ExternalEncoding), input_name='description'), namespace_, eol_))
+            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.description), input_name='description')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1150,12 +1160,12 @@ class tomato_programmer(tomato_person):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
         self.eldate = initvalue_
-        if isinstance(eldatetime, basestring):
+        if isinstance(eldatetime, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime
@@ -1269,10 +1279,10 @@ class tomato_programmer(tomato_person):
         super(tomato_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='programmer')
         if self.language is not None and 'language' not in already_processed:
             already_processed.add('language')
-            outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
+            outfile.write(' language=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.language), input_name='language')), ))
         if self.area is not None and 'area' not in already_processed:
             already_processed.add('area')
-            outfile.write(' area=%s' % (self.gds_format_string(quote_attrib(self.area).encode(ExternalEncoding), input_name='area'), ))
+            outfile.write(' area=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.area), input_name='area')), ))
         if self.attrposint is not None and 'attrposint' not in already_processed:
             already_processed.add('attrposint')
             outfile.write(' attrposint="%s"' % self.gds_format_integer(self.attrposint, input_name='attrposint'))
@@ -1297,7 +1307,7 @@ class tomato_programmer(tomato_person):
             eol_ = ''
         if self.email is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_format_string(quote_xml(self.email).encode(ExternalEncoding), input_name='email'), namespace_, eol_))
+            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.email), input_name='email')), namespace_, eol_))
         if self.elposint is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selposint>%s</%selposint>%s' % (namespace_, self.gds_format_integer(self.elposint, input_name='elposint'), namespace_, eol_))
@@ -1318,7 +1328,7 @@ class tomato_programmer(tomato_person):
             outfile.write('<%seldatetime>%s</%seldatetime>%s' % (namespace_, self.gds_format_datetime(self.eldatetime, input_name='eldatetime'), namespace_, eol_))
         if self.eltoken is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_format_string(quote_xml(self.eltoken).encode(ExternalEncoding), input_name='eltoken'), namespace_, eol_))
+            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.eltoken), input_name='eltoken')), namespace_, eol_))
         if self.elshort is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selshort>%s</%selshort>%s' % (namespace_, self.gds_format_integer(self.elshort, input_name='elshort'), namespace_, eol_))
@@ -1329,7 +1339,7 @@ class tomato_programmer(tomato_person):
             self.elparam.export(outfile, level, namespace_, name_='elparam', pretty_print=pretty_print)
         if self.elarraytypes is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_format_string(quote_xml(self.elarraytypes).encode(ExternalEncoding), input_name='elarraytypes'), namespace_, eol_))
+            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.elarraytypes), input_name='elarraytypes')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1544,7 +1554,7 @@ class tomato_param(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='param')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='param', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1552,7 +1562,7 @@ class tomato_param(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='param'):
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
-            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
+            outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), ))
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
             outfile.write(' name=%s' % (quote_attrib(self.name), ))
@@ -1564,10 +1574,10 @@ class tomato_param(GeneratedsSuper):
             outfile.write(' flow=%s' % (quote_attrib(self.flow), ))
         if self.semantic is not None and 'semantic' not in already_processed:
             already_processed.add('semantic')
-            outfile.write(' semantic=%s' % (self.gds_format_string(quote_attrib(self.semantic).encode(ExternalEncoding), input_name='semantic'), ))
+            outfile.write(' semantic=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.semantic), input_name='semantic')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
-            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
+            outfile.write(' type=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.type_), input_name='type')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='param', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1666,7 +1676,7 @@ class tomato_python_programmer(tomato_programmer):
         super(tomato_python_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='python-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='python-programmer', fromsubclass_=False, pretty_print=True):
         super(tomato_python_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -1675,7 +1685,7 @@ class tomato_python_programmer(tomato_programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1759,10 +1769,10 @@ class tomato_java_programmer(tomato_programmer):
         super(tomato_java_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='java-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
         if self.status is not None and 'status' not in already_processed:
             already_processed.add('status')
-            outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), ))
+            outfile.write(' status=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.status), input_name='status')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='java-programmer', fromsubclass_=False, pretty_print=True):
         super(tomato_java_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -1771,7 +1781,7 @@ class tomato_java_programmer(tomato_programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1869,10 +1879,10 @@ class tomato_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -1983,10 +1993,10 @@ class tomato_special_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -2130,10 +2140,10 @@ class tomato_booster(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.other_name is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sother-name>%s</%sother-name>%s' % (namespace_, self.gds_format_float(self.other_name, input_name='other-name'), namespace_, eol_))
@@ -2263,7 +2273,7 @@ class tomato_info(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='info'):
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
-            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
+            outfile.write(' name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.name), input_name='name')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
             outfile.write(' type="%s"' % self.gds_format_integer(self.type_, input_name='type'))
@@ -2364,7 +2374,7 @@ class tomato_client_handlerType(GeneratedsSuper):
             eol_ = ''
         if self.fullname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fullname).encode(ExternalEncoding), input_name='fullname'), namespace_, eol_))
+            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fullname), input_name='fullname')), namespace_, eol_))
         if self.refid is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srefid>%s</%srefid>%s' % (namespace_, self.gds_format_integer(self.refid, input_name='refid'), namespace_, eol_))
diff --git a/tests/prefix_classname2_sup.py b/tests/prefix_classname2_sup.py
index d607f862e4a5437bcc41c256cf1686d8c7d4d814..8c09004309e71444a7fb66313c58160d55b578d6 100644
--- a/tests/prefix_classname2_sup.py
+++ b/tests/prefix_classname2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1003,7 +1013,7 @@ class tomato_person(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='person'):
         if self.value is not None and 'value' not in already_processed:
             already_processed.add('value')
-            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
+            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), ))
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
             outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
@@ -1012,10 +1022,10 @@ class tomato_person(GeneratedsSuper):
             outfile.write(' ratio="%s"' % self.gds_format_float(self.ratio, input_name='ratio'))
         if self.fruit is not None and 'fruit' not in already_processed:
             already_processed.add('fruit')
-            outfile.write(' fruit=%s' % (self.gds_format_string(quote_attrib(self.fruit).encode(ExternalEncoding), input_name='fruit'), ))
+            outfile.write(' fruit=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.fruit), input_name='fruit')), ))
         if self.vegetable is not None and 'vegetable' not in already_processed:
             already_processed.add('vegetable')
-            outfile.write(' vegetable=%s' % (self.gds_format_string(quote_attrib(self.vegetable).encode(ExternalEncoding), input_name='vegetable'), ))
+            outfile.write(' vegetable=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.vegetable), input_name='vegetable')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -1027,10 +1037,10 @@ class tomato_person(GeneratedsSuper):
             eol_ = ''
         if self.name is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_, eol_))
+            outfile.write('<%sname>%s</%sname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.name), input_name='name')), namespace_, eol_))
         for interest_ in self.interest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_format_string(quote_xml(interest_).encode(ExternalEncoding), input_name='interest'), namespace_, eol_))
+            outfile.write('<%sinterest>%s</%sinterest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(interest_), input_name='interest')), namespace_, eol_))
         if self.category is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%scategory>%s</%scategory>%s' % (namespace_, self.gds_format_integer(self.category, input_name='category'), namespace_, eol_))
@@ -1040,7 +1050,7 @@ class tomato_person(GeneratedsSuper):
             promoter_.export(outfile, level, namespace_, name_='promoter', pretty_print=pretty_print)
         if self.description is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_format_string(quote_xml(self.description).encode(ExternalEncoding), input_name='description'), namespace_, eol_))
+            outfile.write('<%sdescription>%s</%sdescription>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.description), input_name='description')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1150,12 +1160,12 @@ class tomato_programmer(tomato_person):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
         self.eldate = initvalue_
-        if isinstance(eldatetime, basestring):
+        if isinstance(eldatetime, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime
@@ -1269,10 +1279,10 @@ class tomato_programmer(tomato_person):
         super(tomato_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='programmer')
         if self.language is not None and 'language' not in already_processed:
             already_processed.add('language')
-            outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
+            outfile.write(' language=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.language), input_name='language')), ))
         if self.area is not None and 'area' not in already_processed:
             already_processed.add('area')
-            outfile.write(' area=%s' % (self.gds_format_string(quote_attrib(self.area).encode(ExternalEncoding), input_name='area'), ))
+            outfile.write(' area=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.area), input_name='area')), ))
         if self.attrposint is not None and 'attrposint' not in already_processed:
             already_processed.add('attrposint')
             outfile.write(' attrposint="%s"' % self.gds_format_integer(self.attrposint, input_name='attrposint'))
@@ -1297,7 +1307,7 @@ class tomato_programmer(tomato_person):
             eol_ = ''
         if self.email is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_format_string(quote_xml(self.email).encode(ExternalEncoding), input_name='email'), namespace_, eol_))
+            outfile.write('<%semail>%s</%semail>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.email), input_name='email')), namespace_, eol_))
         if self.elposint is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selposint>%s</%selposint>%s' % (namespace_, self.gds_format_integer(self.elposint, input_name='elposint'), namespace_, eol_))
@@ -1318,7 +1328,7 @@ class tomato_programmer(tomato_person):
             outfile.write('<%seldatetime>%s</%seldatetime>%s' % (namespace_, self.gds_format_datetime(self.eldatetime, input_name='eldatetime'), namespace_, eol_))
         if self.eltoken is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_format_string(quote_xml(self.eltoken).encode(ExternalEncoding), input_name='eltoken'), namespace_, eol_))
+            outfile.write('<%seltoken>%s</%seltoken>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.eltoken), input_name='eltoken')), namespace_, eol_))
         if self.elshort is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%selshort>%s</%selshort>%s' % (namespace_, self.gds_format_integer(self.elshort, input_name='elshort'), namespace_, eol_))
@@ -1329,7 +1339,7 @@ class tomato_programmer(tomato_person):
             self.elparam.export(outfile, level, namespace_, name_='elparam', pretty_print=pretty_print)
         if self.elarraytypes is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_format_string(quote_xml(self.elarraytypes).encode(ExternalEncoding), input_name='elarraytypes'), namespace_, eol_))
+            outfile.write('<%selarraytypes>%s</%selarraytypes>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.elarraytypes), input_name='elarraytypes')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1544,7 +1554,7 @@ class tomato_param(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='param')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='param', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -1552,7 +1562,7 @@ class tomato_param(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='param'):
         if self.id is not None and 'id' not in already_processed:
             already_processed.add('id')
-            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
+            outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), ))
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
             outfile.write(' name=%s' % (quote_attrib(self.name), ))
@@ -1564,10 +1574,10 @@ class tomato_param(GeneratedsSuper):
             outfile.write(' flow=%s' % (quote_attrib(self.flow), ))
         if self.semantic is not None and 'semantic' not in already_processed:
             already_processed.add('semantic')
-            outfile.write(' semantic=%s' % (self.gds_format_string(quote_attrib(self.semantic).encode(ExternalEncoding), input_name='semantic'), ))
+            outfile.write(' semantic=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.semantic), input_name='semantic')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
-            outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
+            outfile.write(' type=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.type_), input_name='type')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='param', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -1666,7 +1676,7 @@ class tomato_python_programmer(tomato_programmer):
         super(tomato_python_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='python-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='python-programmer', fromsubclass_=False, pretty_print=True):
         super(tomato_python_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -1675,7 +1685,7 @@ class tomato_python_programmer(tomato_programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1759,10 +1769,10 @@ class tomato_java_programmer(tomato_programmer):
         super(tomato_java_programmer, self).exportAttributes(outfile, level, already_processed, namespace_, name_='java-programmer')
         if self.nick_name is not None and 'nick_name' not in already_processed:
             already_processed.add('nick_name')
-            outfile.write(' nick-name=%s' % (self.gds_format_string(quote_attrib(self.nick_name).encode(ExternalEncoding), input_name='nick-name'), ))
+            outfile.write(' nick-name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.nick_name), input_name='nick-name')), ))
         if self.status is not None and 'status' not in already_processed:
             already_processed.add('status')
-            outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), ))
+            outfile.write(' status=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.status), input_name='status')), ))
     def exportChildren(self, outfile, level, namespace_='', name_='java-programmer', fromsubclass_=False, pretty_print=True):
         super(tomato_java_programmer, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
         if pretty_print:
@@ -1771,7 +1781,7 @@ class tomato_java_programmer(tomato_programmer):
             eol_ = ''
         if self.favorite_editor is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_format_string(quote_xml(self.favorite_editor).encode(ExternalEncoding), input_name='favorite-editor'), namespace_, eol_))
+            outfile.write('<%sfavorite-editor>%s</%sfavorite-editor>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.favorite_editor), input_name='favorite-editor')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -1869,10 +1879,10 @@ class tomato_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -1983,10 +1993,10 @@ class tomato_special_agent(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.priority is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%spriority>%s</%spriority>%s' % (namespace_, self.gds_format_float(self.priority, input_name='priority'), namespace_, eol_))
@@ -2130,10 +2140,10 @@ class tomato_booster(GeneratedsSuper):
             eol_ = ''
         if self.firstname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_format_string(quote_xml(self.firstname).encode(ExternalEncoding), input_name='firstname'), namespace_, eol_))
+            outfile.write('<%sfirstname>%s</%sfirstname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.firstname), input_name='firstname')), namespace_, eol_))
         if self.lastname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lastname).encode(ExternalEncoding), input_name='lastname'), namespace_, eol_))
+            outfile.write('<%slastname>%s</%slastname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lastname), input_name='lastname')), namespace_, eol_))
         if self.other_name is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sother-name>%s</%sother-name>%s' % (namespace_, self.gds_format_float(self.other_name, input_name='other-name'), namespace_, eol_))
@@ -2263,7 +2273,7 @@ class tomato_info(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='info'):
         if self.name is not None and 'name' not in already_processed:
             already_processed.add('name')
-            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
+            outfile.write(' name=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.name), input_name='name')), ))
         if self.type_ is not None and 'type_' not in already_processed:
             already_processed.add('type_')
             outfile.write(' type="%s"' % self.gds_format_integer(self.type_, input_name='type'))
@@ -2364,7 +2374,7 @@ class tomato_client_handlerType(GeneratedsSuper):
             eol_ = ''
         if self.fullname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fullname).encode(ExternalEncoding), input_name='fullname'), namespace_, eol_))
+            outfile.write('<%sfullname>%s</%sfullname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fullname), input_name='fullname')), namespace_, eol_))
         if self.refid is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%srefid>%s</%srefid>%s' % (namespace_, self.gds_format_integer(self.refid, input_name='refid'), namespace_, eol_))
diff --git a/tests/recursive_simpletype1_sup.py b/tests/recursive_simpletype1_sup.py
index f1a56ef1e881f1c3823beefff1e25bc915eabe58..4929b8ea6ac1500554584ba405beaa5a0ea5a0b7 100644
--- a/tests/recursive_simpletype1_sup.py
+++ b/tests/recursive_simpletype1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -702,10 +712,10 @@ class PersonType(GeneratedsSuper):
             outfile.write('<%spersonId>%s</%spersonId>%s' % (namespace_, self.gds_format_integer(self.personId, input_name='personId'), namespace_, eol_))
         if self.fname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfname>%s</%sfname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fname).encode(ExternalEncoding), input_name='fname'), namespace_, eol_))
+            outfile.write('<%sfname>%s</%sfname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fname), input_name='fname')), namespace_, eol_))
         if self.lname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slname>%s</%slname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lname).encode(ExternalEncoding), input_name='lname'), namespace_, eol_))
+            outfile.write('<%slname>%s</%slname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lname), input_name='lname')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/recursive_simpletype2_sup.py b/tests/recursive_simpletype2_sup.py
index f1a56ef1e881f1c3823beefff1e25bc915eabe58..4929b8ea6ac1500554584ba405beaa5a0ea5a0b7 100644
--- a/tests/recursive_simpletype2_sup.py
+++ b/tests/recursive_simpletype2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -702,10 +712,10 @@ class PersonType(GeneratedsSuper):
             outfile.write('<%spersonId>%s</%spersonId>%s' % (namespace_, self.gds_format_integer(self.personId, input_name='personId'), namespace_, eol_))
         if self.fname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sfname>%s</%sfname>%s' % (namespace_, self.gds_format_string(quote_xml(self.fname).encode(ExternalEncoding), input_name='fname'), namespace_, eol_))
+            outfile.write('<%sfname>%s</%sfname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.fname), input_name='fname')), namespace_, eol_))
         if self.lname is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slname>%s</%slname>%s' % (namespace_, self.gds_format_string(quote_xml(self.lname).encode(ExternalEncoding), input_name='lname'), namespace_, eol_))
+            outfile.write('<%slname>%s</%slname>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.lname), input_name='lname')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/reference_simpletype1_sup.py b/tests/reference_simpletype1_sup.py
index bf3d90724bc8c2255adc187058bc09fcd1fd0d1b..ab1f0843e4e6f98c594a0db59bf4219b7219af9e 100644
--- a/tests/reference_simpletype1_sup.py
+++ b/tests/reference_simpletype1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
diff --git a/tests/reference_simpletype2_sup.py b/tests/reference_simpletype2_sup.py
index bf3d90724bc8c2255adc187058bc09fcd1fd0d1b..ab1f0843e4e6f98c594a0db59bf4219b7219af9e 100644
--- a/tests/reference_simpletype2_sup.py
+++ b/tests/reference_simpletype2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
diff --git a/tests/simplecontent_restriction1_sup.py b/tests/simplecontent_restriction1_sup.py
index f069bc6fd4648a062be453677d39a4aa71e0a711..5cd34d305be2523a47af5d1398a0099ccc2de49b 100644
--- a/tests/simplecontent_restriction1_sup.py
+++ b/tests/simplecontent_restriction1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -706,7 +716,7 @@ class IdentifierType(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='IdentifierType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='IdentifierType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -714,25 +724,25 @@ class IdentifierType(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='IdentifierType'):
         if self.schemeID is not None and 'schemeID' not in already_processed:
             already_processed.add('schemeID')
-            outfile.write(' schemeID=%s' % (self.gds_format_string(quote_attrib(self.schemeID).encode(ExternalEncoding), input_name='schemeID'), ))
+            outfile.write(' schemeID=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeID), input_name='schemeID')), ))
         if self.schemeName is not None and 'schemeName' not in already_processed:
             already_processed.add('schemeName')
-            outfile.write(' schemeName=%s' % (self.gds_format_string(quote_attrib(self.schemeName).encode(ExternalEncoding), input_name='schemeName'), ))
+            outfile.write(' schemeName=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeName), input_name='schemeName')), ))
         if self.schemeAgencyID is not None and 'schemeAgencyID' not in already_processed:
             already_processed.add('schemeAgencyID')
-            outfile.write(' schemeAgencyID=%s' % (self.gds_format_string(quote_attrib(self.schemeAgencyID).encode(ExternalEncoding), input_name='schemeAgencyID'), ))
+            outfile.write(' schemeAgencyID=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeAgencyID), input_name='schemeAgencyID')), ))
         if self.schemeAgencyName is not None and 'schemeAgencyName' not in already_processed:
             already_processed.add('schemeAgencyName')
-            outfile.write(' schemeAgencyName=%s' % (self.gds_format_string(quote_attrib(self.schemeAgencyName).encode(ExternalEncoding), input_name='schemeAgencyName'), ))
+            outfile.write(' schemeAgencyName=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeAgencyName), input_name='schemeAgencyName')), ))
         if self.schemeVersionID is not None and 'schemeVersionID' not in already_processed:
             already_processed.add('schemeVersionID')
-            outfile.write(' schemeVersionID=%s' % (self.gds_format_string(quote_attrib(self.schemeVersionID).encode(ExternalEncoding), input_name='schemeVersionID'), ))
+            outfile.write(' schemeVersionID=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeVersionID), input_name='schemeVersionID')), ))
         if self.schemeDataURI is not None and 'schemeDataURI' not in already_processed:
             already_processed.add('schemeDataURI')
-            outfile.write(' schemeDataURI=%s' % (self.gds_format_string(quote_attrib(self.schemeDataURI).encode(ExternalEncoding), input_name='schemeDataURI'), ))
+            outfile.write(' schemeDataURI=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeDataURI), input_name='schemeDataURI')), ))
         if self.schemeURI is not None and 'schemeURI' not in already_processed:
             already_processed.add('schemeURI')
-            outfile.write(' schemeURI=%s' % (self.gds_format_string(quote_attrib(self.schemeURI).encode(ExternalEncoding), input_name='schemeURI'), ))
+            outfile.write(' schemeURI=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeURI), input_name='schemeURI')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -829,7 +839,7 @@ class BillOfResourcesIDType(IdentifierType):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='BillOfResourcesIDType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfResourcesIDType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -898,7 +908,7 @@ class BillOfMaterialIDType(IdentifierType):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='BillOfMaterialIDType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfMaterialIDType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
diff --git a/tests/simplecontent_restriction2_sup.py b/tests/simplecontent_restriction2_sup.py
index f069bc6fd4648a062be453677d39a4aa71e0a711..5cd34d305be2523a47af5d1398a0099ccc2de49b 100644
--- a/tests/simplecontent_restriction2_sup.py
+++ b/tests/simplecontent_restriction2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -706,7 +716,7 @@ class IdentifierType(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='IdentifierType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='IdentifierType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -714,25 +724,25 @@ class IdentifierType(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='IdentifierType'):
         if self.schemeID is not None and 'schemeID' not in already_processed:
             already_processed.add('schemeID')
-            outfile.write(' schemeID=%s' % (self.gds_format_string(quote_attrib(self.schemeID).encode(ExternalEncoding), input_name='schemeID'), ))
+            outfile.write(' schemeID=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeID), input_name='schemeID')), ))
         if self.schemeName is not None and 'schemeName' not in already_processed:
             already_processed.add('schemeName')
-            outfile.write(' schemeName=%s' % (self.gds_format_string(quote_attrib(self.schemeName).encode(ExternalEncoding), input_name='schemeName'), ))
+            outfile.write(' schemeName=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeName), input_name='schemeName')), ))
         if self.schemeAgencyID is not None and 'schemeAgencyID' not in already_processed:
             already_processed.add('schemeAgencyID')
-            outfile.write(' schemeAgencyID=%s' % (self.gds_format_string(quote_attrib(self.schemeAgencyID).encode(ExternalEncoding), input_name='schemeAgencyID'), ))
+            outfile.write(' schemeAgencyID=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeAgencyID), input_name='schemeAgencyID')), ))
         if self.schemeAgencyName is not None and 'schemeAgencyName' not in already_processed:
             already_processed.add('schemeAgencyName')
-            outfile.write(' schemeAgencyName=%s' % (self.gds_format_string(quote_attrib(self.schemeAgencyName).encode(ExternalEncoding), input_name='schemeAgencyName'), ))
+            outfile.write(' schemeAgencyName=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeAgencyName), input_name='schemeAgencyName')), ))
         if self.schemeVersionID is not None and 'schemeVersionID' not in already_processed:
             already_processed.add('schemeVersionID')
-            outfile.write(' schemeVersionID=%s' % (self.gds_format_string(quote_attrib(self.schemeVersionID).encode(ExternalEncoding), input_name='schemeVersionID'), ))
+            outfile.write(' schemeVersionID=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeVersionID), input_name='schemeVersionID')), ))
         if self.schemeDataURI is not None and 'schemeDataURI' not in already_processed:
             already_processed.add('schemeDataURI')
-            outfile.write(' schemeDataURI=%s' % (self.gds_format_string(quote_attrib(self.schemeDataURI).encode(ExternalEncoding), input_name='schemeDataURI'), ))
+            outfile.write(' schemeDataURI=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeDataURI), input_name='schemeDataURI')), ))
         if self.schemeURI is not None and 'schemeURI' not in already_processed:
             already_processed.add('schemeURI')
-            outfile.write(' schemeURI=%s' % (self.gds_format_string(quote_attrib(self.schemeURI).encode(ExternalEncoding), input_name='schemeURI'), ))
+            outfile.write(' schemeURI=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.schemeURI), input_name='schemeURI')), ))
         if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
             already_processed.add('xsi:type')
             outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
@@ -829,7 +839,7 @@ class BillOfResourcesIDType(IdentifierType):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='BillOfResourcesIDType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfResourcesIDType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -898,7 +908,7 @@ class BillOfMaterialIDType(IdentifierType):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='BillOfMaterialIDType')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfMaterialIDType', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
diff --git a/tests/simpletype_memberspecs1_sup.py b/tests/simpletype_memberspecs1_sup.py
index 85d473d3ccb2e3efdbfcea6442bbc3933ea45a23..5fc9d99ae91f207550571321013b7346494395f3 100644
--- a/tests/simpletype_memberspecs1_sup.py
+++ b/tests/simpletype_memberspecs1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -679,7 +689,7 @@ class SpecialDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='SpecialDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='pl:', name_='SpecialDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -687,7 +697,7 @@ class SpecialDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='pl:', name_='SpecialDate'):
         if self.SpecialProperty is not None and 'SpecialProperty' not in already_processed:
             already_processed.add('SpecialProperty')
-            outfile.write(' SpecialProperty=%s' % (self.gds_format_string(quote_attrib(self.SpecialProperty).encode(ExternalEncoding), input_name='SpecialProperty'), ))
+            outfile.write(' SpecialProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.SpecialProperty), input_name='SpecialProperty')), ))
     def exportChildren(self, outfile, level, namespace_='pl:', name_='SpecialDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -754,7 +764,7 @@ class ExtremeDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='ExtremeDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='pl:', name_='ExtremeDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -762,7 +772,7 @@ class ExtremeDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='pl:', name_='ExtremeDate'):
         if self.ExtremeProperty is not None and 'ExtremeProperty' not in already_processed:
             already_processed.add('ExtremeProperty')
-            outfile.write(' ExtremeProperty=%s' % (self.gds_format_string(quote_attrib(self.ExtremeProperty).encode(ExternalEncoding), input_name='ExtremeProperty'), ))
+            outfile.write(' ExtremeProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.ExtremeProperty), input_name='ExtremeProperty')), ))
     def exportChildren(self, outfile, level, namespace_='pl:', name_='ExtremeDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
diff --git a/tests/simpletype_memberspecs2_sup.py b/tests/simpletype_memberspecs2_sup.py
index 85d473d3ccb2e3efdbfcea6442bbc3933ea45a23..5fc9d99ae91f207550571321013b7346494395f3 100644
--- a/tests/simpletype_memberspecs2_sup.py
+++ b/tests/simpletype_memberspecs2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -679,7 +689,7 @@ class SpecialDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='SpecialDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='pl:', name_='SpecialDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -687,7 +697,7 @@ class SpecialDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='pl:', name_='SpecialDate'):
         if self.SpecialProperty is not None and 'SpecialProperty' not in already_processed:
             already_processed.add('SpecialProperty')
-            outfile.write(' SpecialProperty=%s' % (self.gds_format_string(quote_attrib(self.SpecialProperty).encode(ExternalEncoding), input_name='SpecialProperty'), ))
+            outfile.write(' SpecialProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.SpecialProperty), input_name='SpecialProperty')), ))
     def exportChildren(self, outfile, level, namespace_='pl:', name_='SpecialDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
@@ -754,7 +764,7 @@ class ExtremeDate(GeneratedsSuper):
         self.exportAttributes(outfile, level, already_processed, namespace_, name_='ExtremeDate')
         if self.hasContent_():
             outfile.write('>')
-            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else str(self.valueOf_)).encode(ExternalEncoding))
+            outfile.write((quote_xml(self.valueOf_) if type(self.valueOf_) is str else self.gds_encode(str(self.valueOf_))))
             self.exportChildren(outfile, level + 1, namespace_='pl:', name_='ExtremeDate', pretty_print=pretty_print)
             outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
         else:
@@ -762,7 +772,7 @@ class ExtremeDate(GeneratedsSuper):
     def exportAttributes(self, outfile, level, already_processed, namespace_='pl:', name_='ExtremeDate'):
         if self.ExtremeProperty is not None and 'ExtremeProperty' not in already_processed:
             already_processed.add('ExtremeProperty')
-            outfile.write(' ExtremeProperty=%s' % (self.gds_format_string(quote_attrib(self.ExtremeProperty).encode(ExternalEncoding), input_name='ExtremeProperty'), ))
+            outfile.write(' ExtremeProperty=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.ExtremeProperty), input_name='ExtremeProperty')), ))
     def exportChildren(self, outfile, level, namespace_='pl:', name_='ExtremeDate', fromsubclass_=False, pretty_print=True):
         pass
     def build(self, node):
diff --git a/tests/simpletypes_other1_sup.py b/tests/simpletypes_other1_sup.py
index b12e1b9482132c4921af5480e3eb33ee988198e5..0d25affee9ca0d1a369d1322ca08512f8a7b7c35 100644
--- a/tests/simpletypes_other1_sup.py
+++ b/tests/simpletypes_other1_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class simpleTypeTestsType(GeneratedsSuper):
             eol_ = ''
         for simpleTypeTest_ in self.simpleTypeTest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%ssimpleTypeTest>%s</%ssimpleTypeTest>%s' % (namespace_, self.gds_format_string(quote_xml(simpleTypeTest_).encode(ExternalEncoding), input_name='simpleTypeTest'), namespace_, eol_))
+            outfile.write('<%ssimpleTypeTest>%s</%ssimpleTypeTest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(simpleTypeTest_), input_name='simpleTypeTest')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -776,7 +786,7 @@ class simpleTypeTest(GeneratedsSuper):
             self.floatVal2 = []
         else:
             self.floatVal2 = floatVal2
-        if isinstance(dateVal1, basestring):
+        if isinstance(dateVal1, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(dateVal1, '%Y-%m-%d').date()
         else:
             initvalue_ = dateVal1
@@ -785,7 +795,7 @@ class simpleTypeTest(GeneratedsSuper):
             self.dateVal2 = []
         else:
             self.dateVal2 = dateVal2
-        if isinstance(dateTimeVal1, basestring):
+        if isinstance(dateTimeVal1, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(dateTimeVal1, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = dateTimeVal1
@@ -925,19 +935,19 @@ class simpleTypeTest(GeneratedsSuper):
             eol_ = ''
         if self.datetime1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime1>%s</%sdatetime1>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime1).encode(ExternalEncoding), input_name='datetime1'), namespace_, eol_))
+            outfile.write('<%sdatetime1>%s</%sdatetime1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime1), input_name='datetime1')), namespace_, eol_))
         if self.datetime2 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime2>%s</%sdatetime2>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime2).encode(ExternalEncoding), input_name='datetime2'), namespace_, eol_))
+            outfile.write('<%sdatetime2>%s</%sdatetime2>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime2), input_name='datetime2')), namespace_, eol_))
         if self.datetime3 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime3>%s</%sdatetime3>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime3).encode(ExternalEncoding), input_name='datetime3'), namespace_, eol_))
+            outfile.write('<%sdatetime3>%s</%sdatetime3>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime3), input_name='datetime3')), namespace_, eol_))
         if self.datetime4 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime4>%s</%sdatetime4>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime4).encode(ExternalEncoding), input_name='datetime4'), namespace_, eol_))
+            outfile.write('<%sdatetime4>%s</%sdatetime4>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime4), input_name='datetime4')), namespace_, eol_))
         if self.datetime5 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime5>%s</%sdatetime5>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime5).encode(ExternalEncoding), input_name='datetime5'), namespace_, eol_))
+            outfile.write('<%sdatetime5>%s</%sdatetime5>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime5), input_name='datetime5')), namespace_, eol_))
         if self.integerVal1 is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sintegerVal1>%s</%sintegerVal1>%s' % (namespace_, self.gds_format_integer(self.integerVal1, input_name='integerVal1'), namespace_, eol_))
@@ -946,10 +956,10 @@ class simpleTypeTest(GeneratedsSuper):
             outfile.write('<%sintegerVal2>%s</%sintegerVal2>%s' % (namespace_, self.gds_format_integer(integerVal2_, input_name='integerVal2'), namespace_, eol_))
         if self.stringVal1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstringVal1>%s</%sstringVal1>%s' % (namespace_, self.gds_format_string(quote_xml(self.stringVal1).encode(ExternalEncoding), input_name='stringVal1'), namespace_, eol_))
+            outfile.write('<%sstringVal1>%s</%sstringVal1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.stringVal1), input_name='stringVal1')), namespace_, eol_))
         for stringVal2_ in self.stringVal2:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstringVal2>%s</%sstringVal2>%s' % (namespace_, self.gds_format_string(quote_xml(stringVal2_).encode(ExternalEncoding), input_name='stringVal2'), namespace_, eol_))
+            outfile.write('<%sstringVal2>%s</%sstringVal2>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(stringVal2_), input_name='stringVal2')), namespace_, eol_))
         if self.booleanVal1 is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sbooleanVal1>%s</%sbooleanVal1>%s' % (namespace_, self.gds_format_boolean(self.booleanVal1, input_name='booleanVal1'), namespace_, eol_))
diff --git a/tests/simpletypes_other2_sup.py b/tests/simpletypes_other2_sup.py
index b12e1b9482132c4921af5480e3eb33ee988198e5..0d25affee9ca0d1a369d1322ca08512f8a7b7c35 100644
--- a/tests/simpletypes_other2_sup.py
+++ b/tests/simpletypes_other2_sup.py
@@ -33,6 +33,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -352,6 +356,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -406,7 +416,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -428,7 +438,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -695,7 +705,7 @@ class simpleTypeTestsType(GeneratedsSuper):
             eol_ = ''
         for simpleTypeTest_ in self.simpleTypeTest:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%ssimpleTypeTest>%s</%ssimpleTypeTest>%s' % (namespace_, self.gds_format_string(quote_xml(simpleTypeTest_).encode(ExternalEncoding), input_name='simpleTypeTest'), namespace_, eol_))
+            outfile.write('<%ssimpleTypeTest>%s</%ssimpleTypeTest>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(simpleTypeTest_), input_name='simpleTypeTest')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
@@ -776,7 +786,7 @@ class simpleTypeTest(GeneratedsSuper):
             self.floatVal2 = []
         else:
             self.floatVal2 = floatVal2
-        if isinstance(dateVal1, basestring):
+        if isinstance(dateVal1, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(dateVal1, '%Y-%m-%d').date()
         else:
             initvalue_ = dateVal1
@@ -785,7 +795,7 @@ class simpleTypeTest(GeneratedsSuper):
             self.dateVal2 = []
         else:
             self.dateVal2 = dateVal2
-        if isinstance(dateTimeVal1, basestring):
+        if isinstance(dateTimeVal1, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(dateTimeVal1, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = dateTimeVal1
@@ -925,19 +935,19 @@ class simpleTypeTest(GeneratedsSuper):
             eol_ = ''
         if self.datetime1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime1>%s</%sdatetime1>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime1).encode(ExternalEncoding), input_name='datetime1'), namespace_, eol_))
+            outfile.write('<%sdatetime1>%s</%sdatetime1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime1), input_name='datetime1')), namespace_, eol_))
         if self.datetime2 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime2>%s</%sdatetime2>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime2).encode(ExternalEncoding), input_name='datetime2'), namespace_, eol_))
+            outfile.write('<%sdatetime2>%s</%sdatetime2>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime2), input_name='datetime2')), namespace_, eol_))
         if self.datetime3 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime3>%s</%sdatetime3>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime3).encode(ExternalEncoding), input_name='datetime3'), namespace_, eol_))
+            outfile.write('<%sdatetime3>%s</%sdatetime3>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime3), input_name='datetime3')), namespace_, eol_))
         if self.datetime4 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime4>%s</%sdatetime4>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime4).encode(ExternalEncoding), input_name='datetime4'), namespace_, eol_))
+            outfile.write('<%sdatetime4>%s</%sdatetime4>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime4), input_name='datetime4')), namespace_, eol_))
         if self.datetime5 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sdatetime5>%s</%sdatetime5>%s' % (namespace_, self.gds_format_string(quote_xml(self.datetime5).encode(ExternalEncoding), input_name='datetime5'), namespace_, eol_))
+            outfile.write('<%sdatetime5>%s</%sdatetime5>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.datetime5), input_name='datetime5')), namespace_, eol_))
         if self.integerVal1 is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sintegerVal1>%s</%sintegerVal1>%s' % (namespace_, self.gds_format_integer(self.integerVal1, input_name='integerVal1'), namespace_, eol_))
@@ -946,10 +956,10 @@ class simpleTypeTest(GeneratedsSuper):
             outfile.write('<%sintegerVal2>%s</%sintegerVal2>%s' % (namespace_, self.gds_format_integer(integerVal2_, input_name='integerVal2'), namespace_, eol_))
         if self.stringVal1 is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstringVal1>%s</%sstringVal1>%s' % (namespace_, self.gds_format_string(quote_xml(self.stringVal1).encode(ExternalEncoding), input_name='stringVal1'), namespace_, eol_))
+            outfile.write('<%sstringVal1>%s</%sstringVal1>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.stringVal1), input_name='stringVal1')), namespace_, eol_))
         for stringVal2_ in self.stringVal2:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%sstringVal2>%s</%sstringVal2>%s' % (namespace_, self.gds_format_string(quote_xml(stringVal2_).encode(ExternalEncoding), input_name='stringVal2'), namespace_, eol_))
+            outfile.write('<%sstringVal2>%s</%sstringVal2>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(stringVal2_), input_name='stringVal2')), namespace_, eol_))
         if self.booleanVal1 is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sbooleanVal1>%s</%sbooleanVal1>%s' % (namespace_, self.gds_format_boolean(self.booleanVal1, input_name='booleanVal1'), namespace_, eol_))
diff --git a/tests/test.py b/tests/test.py
index 2a91d7510eeb998a76064e1bab6eb1e67cddf1b1..64df9a0304d040289a003bf316f034ee85c07c68 100755
--- a/tests/test.py
+++ b/tests/test.py
@@ -657,7 +657,7 @@ class GenTest(unittest.TestCase):
     def test_029_defaults_cases(self):
         cmdTempl = (
             'python generateDS.py --no-dates --no-versions '
-            '--silence --member-specs=list -f '
+            '--member-specs=list -f '
             '-o tests/%s2_sup.py -s tests/%s2_sub.py '
             '--super=%s2_sup '
             'tests/%s.xsd'
diff --git a/tests/to_etree1_sup.py b/tests/to_etree1_sup.py
index b513bbbcfcb866defa0bd8eca265b018fd790a08..c697e58671261c3055c9e61e7c9347e5795ac2e1 100644
--- a/tests/to_etree1_sup.py
+++ b/tests/to_etree1_sup.py
@@ -35,6 +35,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -354,6 +358,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -408,7 +418,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -430,7 +440,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1215,17 +1225,17 @@ class programmerType(personType):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
         self.eldate = initvalue_
-        if isinstance(eldatetime, basestring):
+        if isinstance(eldatetime, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime
         self.eldatetime = initvalue_
-        if isinstance(eldatetime1, basestring):
+        if isinstance(eldatetime1, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime1, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime1
@@ -2688,7 +2698,7 @@ class hot_agent(GeneratedsSuper):
         self.firstname = firstname
         self.lastname = lastname
         self.priority = priority
-        if isinstance(startDate, basestring):
+        if isinstance(startDate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(startDate, '%Y-%m-%d').date()
         else:
             initvalue_ = startDate
diff --git a/tests/to_etree2_sup.py b/tests/to_etree2_sup.py
index b513bbbcfcb866defa0bd8eca265b018fd790a08..c697e58671261c3055c9e61e7c9347e5795ac2e1 100644
--- a/tests/to_etree2_sup.py
+++ b/tests/to_etree2_sup.py
@@ -35,6 +35,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -354,6 +358,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -408,7 +418,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -430,7 +440,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -1215,17 +1225,17 @@ class programmerType(personType):
         self.elnonposint = elnonposint
         self.elnegint = elnegint
         self.elnonnegint = elnonnegint
-        if isinstance(eldate, basestring):
+        if isinstance(eldate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldate, '%Y-%m-%d').date()
         else:
             initvalue_ = eldate
         self.eldate = initvalue_
-        if isinstance(eldatetime, basestring):
+        if isinstance(eldatetime, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime
         self.eldatetime = initvalue_
-        if isinstance(eldatetime1, basestring):
+        if isinstance(eldatetime1, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(eldatetime1, '%Y-%m-%dT%H:%M:%S')
         else:
             initvalue_ = eldatetime1
@@ -2688,7 +2698,7 @@ class hot_agent(GeneratedsSuper):
         self.firstname = firstname
         self.lastname = lastname
         self.priority = priority
-        if isinstance(startDate, basestring):
+        if isinstance(startDate, BaseStrType_):
             initvalue_ = datetime_.datetime.strptime(startDate, '%Y-%m-%d').date()
         else:
             initvalue_ = startDate
diff --git a/tests/validate_simpletypes1_sup.py b/tests/validate_simpletypes1_sup.py
index 03eb6740484078fe5c8ffdd97f0cc915725ad6de..30547aa64451f9d155d2161f8251c12514c13a89 100644
--- a/tests/validate_simpletypes1_sup.py
+++ b/tests/validate_simpletypes1_sup.py
@@ -32,6 +32,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -351,6 +355,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -405,7 +415,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -427,7 +437,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -974,13 +984,13 @@ class simpleOneType(GeneratedsSuper):
             outfile.write('<%sinteger_range_1_value>%s</%sinteger_range_1_value>%s' % (namespace_, self.gds_format_integer(self.integer_range_1_value, input_name='integer_range_1_value'), namespace_, eol_))
         if self.pattern_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%spattern_value>%s</%spattern_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.pattern_value).encode(ExternalEncoding), input_name='pattern_value'), namespace_, eol_))
+            outfile.write('<%spattern_value>%s</%spattern_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.pattern_value), input_name='pattern_value')), namespace_, eol_))
         if self.token_enum_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.token_enum_value).encode(ExternalEncoding), input_name='token_enum_value'), namespace_, eol_))
+            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.token_enum_value), input_name='token_enum_value')), namespace_, eol_))
         if self.token_enum_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.token_enum_value).encode(ExternalEncoding), input_name='token_enum_value'), namespace_, eol_))
+            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.token_enum_value), input_name='token_enum_value')), namespace_, eol_))
         if self.integer_range_incl_value is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_range_incl_value>%s</%sinteger_range_incl_value>%s' % (namespace_, self.gds_format_integer(self.integer_range_incl_value, input_name='integer_range_incl_value'), namespace_, eol_))
@@ -989,10 +999,10 @@ class simpleOneType(GeneratedsSuper):
             outfile.write('<%sinteger_range_excl_value>%s</%sinteger_range_excl_value>%s' % (namespace_, self.gds_format_integer(self.integer_range_excl_value, input_name='integer_range_excl_value'), namespace_, eol_))
         if self.min_max_length_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%smin_max_length_value>%s</%smin_max_length_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.min_max_length_value).encode(ExternalEncoding), input_name='min_max_length_value'), namespace_, eol_))
+            outfile.write('<%smin_max_length_value>%s</%smin_max_length_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.min_max_length_value), input_name='min_max_length_value')), namespace_, eol_))
         if self.length_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slength_value>%s</%slength_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.length_value).encode(ExternalEncoding), input_name='length_value'), namespace_, eol_))
+            outfile.write('<%slength_value>%s</%slength_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.length_value), input_name='length_value')), namespace_, eol_))
         if self.totalDigits_value is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%stotalDigits_value>%s</%stotalDigits_value>%s' % (namespace_, self.gds_format_float(self.totalDigits_value, input_name='totalDigits_value'), namespace_, eol_))
@@ -1252,7 +1262,7 @@ class simpleTwoElementOneType(GeneratedsSuper):
             eol_ = ''
         if self.simpleTwoElementTwo is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%ssimpleTwoElementTwo>%s</%ssimpleTwoElementTwo>%s' % (namespace_, self.gds_format_string(quote_xml(self.simpleTwoElementTwo).encode(ExternalEncoding), input_name='simpleTwoElementTwo'), namespace_, eol_))
+            outfile.write('<%ssimpleTwoElementTwo>%s</%ssimpleTwoElementTwo>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.simpleTwoElementTwo), input_name='simpleTwoElementTwo')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/validate_simpletypes1_warnings.txt b/tests/validate_simpletypes1_warnings.txt
index 243afeda4eb08cad0f08d60449a78ce7b3f23e80..a6a01c2cddc0cf7e5ac14d496f654503641c0a56 100644
--- a/tests/validate_simpletypes1_warnings.txt
+++ b/tests/validate_simpletypes1_warnings.txt
@@ -1,34 +1,34 @@
-tests/validate_simpletypes2_sup.py:867: UserWarning: Value "2" does not match xsd minExclusive restriction on integer_range_1_st
+tests/validate_simpletypes2_sup.py:877: UserWarning: Value "2" does not match xsd minExclusive restriction on integer_range_1_st
   warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on integer_range_1_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:877: UserWarning: Value "mmaaa1234mnopzzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
+tests/validate_simpletypes2_sup.py:887: UserWarning: Value "mmaaa1234mnopzzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
   warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, ))
-tests/validate_simpletypes2_sup.py:890: UserWarning: Value "floatxx" does not match xsd enumeration restriction on token_enum_st
+tests/validate_simpletypes2_sup.py:900: UserWarning: Value "floatxx" does not match xsd enumeration restriction on token_enum_st
   warnings_.warn('Value "%(value)s" does not match xsd enumeration restriction on token_enum_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:897: UserWarning: Value "22" does not match xsd maxInclusive restriction on integer_range_incl_st
+tests/validate_simpletypes2_sup.py:907: UserWarning: Value "22" does not match xsd maxInclusive restriction on integer_range_incl_st
   warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on integer_range_incl_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:902: UserWarning: Value "-40" does not match xsd minExclusive restriction on integer_range_excl_st
+tests/validate_simpletypes2_sup.py:912: UserWarning: Value "-40" does not match xsd minExclusive restriction on integer_range_excl_st
   warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on integer_range_excl_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:911: UserWarning: Value "mno pqr" does not match xsd minLength restriction on min_max_length_st
+tests/validate_simpletypes2_sup.py:921: UserWarning: Value "mno pqr" does not match xsd minLength restriction on min_max_length_st
   warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on min_max_length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:916: UserWarning: Value "012345" does not match xsd length restriction on length_st
+tests/validate_simpletypes2_sup.py:926: UserWarning: Value "012345" does not match xsd length restriction on length_st
   warnings_.warn('Value "%(value)s" does not match xsd length restriction on length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:926: UserWarning: Value "0.2" does not match xsd minInclusive restriction on anonymous_float_valueType
+tests/validate_simpletypes2_sup.py:936: UserWarning: Value "0.2" does not match xsd minInclusive restriction on anonymous_float_valueType
   warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on anonymous_float_valueType' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:869: UserWarning: Value "9" does not match xsd maxExclusive restriction on integer_range_1_st
+tests/validate_simpletypes2_sup.py:879: UserWarning: Value "9" does not match xsd maxExclusive restriction on integer_range_1_st
   warnings_.warn('Value "%(value)s" does not match xsd maxExclusive restriction on integer_range_1_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:877: UserWarning: Value "aaa1234mnopzzzbcd" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
+tests/validate_simpletypes2_sup.py:887: UserWarning: Value "aaa1234mnopzzzbcd" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
   warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, ))
-tests/validate_simpletypes2_sup.py:895: UserWarning: Value "-50" does not match xsd minInclusive restriction on integer_range_incl_st
+tests/validate_simpletypes2_sup.py:905: UserWarning: Value "-50" does not match xsd minInclusive restriction on integer_range_incl_st
   warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on integer_range_incl_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:909: UserWarning: Value "asdf asdf asdf asdf asdf asdf" does not match xsd maxLength restriction on min_max_length_st
+tests/validate_simpletypes2_sup.py:919: UserWarning: Value "asdf asdf asdf asdf asdf asdf" does not match xsd maxLength restriction on min_max_length_st
   warnings_.warn('Value "%(value)s" does not match xsd maxLength restriction on min_max_length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:916: UserWarning: Value "01234567890" does not match xsd length restriction on length_st
+tests/validate_simpletypes2_sup.py:926: UserWarning: Value "01234567890" does not match xsd length restriction on length_st
   warnings_.warn('Value "%(value)s" does not match xsd length restriction on length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:928: UserWarning: Value "6.6" does not match xsd maxInclusive restriction on anonymous_float_valueType
+tests/validate_simpletypes2_sup.py:938: UserWarning: Value "6.6" does not match xsd maxInclusive restriction on anonymous_float_valueType
   warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on anonymous_float_valueType' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:874: UserWarning: Value "aaa12zzz" does not match xsd minLength restriction on pattern_st
+tests/validate_simpletypes2_sup.py:884: UserWarning: Value "aaa12zzz" does not match xsd minLength restriction on pattern_st
   warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on pattern_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:877: UserWarning: Value "aaa12zzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
+tests/validate_simpletypes2_sup.py:887: UserWarning: Value "aaa12zzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
   warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, ))
-tests/validate_simpletypes2_sup.py:1220: UserWarning: Value "pqrst" does not match xsd minLength restriction on simpleTwoElementTwoType
+tests/validate_simpletypes2_sup.py:1230: UserWarning: Value "pqrst" does not match xsd minLength restriction on simpleTwoElementTwoType
   warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on simpleTwoElementTwoType' % {"value" : value.encode("utf-8")} )
diff --git a/tests/validate_simpletypes2_sup.py b/tests/validate_simpletypes2_sup.py
index 03eb6740484078fe5c8ffdd97f0cc915725ad6de..30547aa64451f9d155d2161f8251c12514c13a89 100644
--- a/tests/validate_simpletypes2_sup.py
+++ b/tests/validate_simpletypes2_sup.py
@@ -32,6 +32,10 @@ from lxml import etree as etree_
 
 
 Validate_simpletypes_ = True
+if sys.version_info.major == 2:
+    BaseStrType_ = basestring
+else:
+    BaseStrType_ = str
 
 
 def parsexml_(infile, parser=None, **kwargs):
@@ -351,6 +355,12 @@ except ImportError as exp:
         @classmethod
         def gds_reverse_node_mapping(cls, mapping):
             return dict(((v, k) for k, v in mapping.iteritems()))
+        @staticmethod
+        def gds_encode(instring):
+            if sys.version_info.major == 2:
+                return instring.encode(ExternalEncoding)
+            else:
+                return instring
 
     def getSubclassFromModule_(module, class_):
         '''Get the subclass of a class from a specific module.'''
@@ -405,7 +415,7 @@ def quote_xml(inStr):
     "Escape markup chars, but do not modify CDATA sections."
     if not inStr:
         return ''
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s2 = ''
     pos = 0
     matchobjects = CDATA_pattern_.finditer(s1)
@@ -427,7 +437,7 @@ def quote_xml_aux(inStr):
 
 
 def quote_attrib(inStr):
-    s1 = (isinstance(inStr, basestring) and inStr or '%s' % inStr)
+    s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr)
     s1 = s1.replace('&', '&amp;')
     s1 = s1.replace('<', '&lt;')
     s1 = s1.replace('>', '&gt;')
@@ -974,13 +984,13 @@ class simpleOneType(GeneratedsSuper):
             outfile.write('<%sinteger_range_1_value>%s</%sinteger_range_1_value>%s' % (namespace_, self.gds_format_integer(self.integer_range_1_value, input_name='integer_range_1_value'), namespace_, eol_))
         if self.pattern_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%spattern_value>%s</%spattern_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.pattern_value).encode(ExternalEncoding), input_name='pattern_value'), namespace_, eol_))
+            outfile.write('<%spattern_value>%s</%spattern_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.pattern_value), input_name='pattern_value')), namespace_, eol_))
         if self.token_enum_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.token_enum_value).encode(ExternalEncoding), input_name='token_enum_value'), namespace_, eol_))
+            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.token_enum_value), input_name='token_enum_value')), namespace_, eol_))
         if self.token_enum_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.token_enum_value).encode(ExternalEncoding), input_name='token_enum_value'), namespace_, eol_))
+            outfile.write('<%stoken_enum_value>%s</%stoken_enum_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.token_enum_value), input_name='token_enum_value')), namespace_, eol_))
         if self.integer_range_incl_value is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%sinteger_range_incl_value>%s</%sinteger_range_incl_value>%s' % (namespace_, self.gds_format_integer(self.integer_range_incl_value, input_name='integer_range_incl_value'), namespace_, eol_))
@@ -989,10 +999,10 @@ class simpleOneType(GeneratedsSuper):
             outfile.write('<%sinteger_range_excl_value>%s</%sinteger_range_excl_value>%s' % (namespace_, self.gds_format_integer(self.integer_range_excl_value, input_name='integer_range_excl_value'), namespace_, eol_))
         if self.min_max_length_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%smin_max_length_value>%s</%smin_max_length_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.min_max_length_value).encode(ExternalEncoding), input_name='min_max_length_value'), namespace_, eol_))
+            outfile.write('<%smin_max_length_value>%s</%smin_max_length_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.min_max_length_value), input_name='min_max_length_value')), namespace_, eol_))
         if self.length_value is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%slength_value>%s</%slength_value>%s' % (namespace_, self.gds_format_string(quote_xml(self.length_value).encode(ExternalEncoding), input_name='length_value'), namespace_, eol_))
+            outfile.write('<%slength_value>%s</%slength_value>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.length_value), input_name='length_value')), namespace_, eol_))
         if self.totalDigits_value is not None:
             showIndent(outfile, level, pretty_print)
             outfile.write('<%stotalDigits_value>%s</%stotalDigits_value>%s' % (namespace_, self.gds_format_float(self.totalDigits_value, input_name='totalDigits_value'), namespace_, eol_))
@@ -1252,7 +1262,7 @@ class simpleTwoElementOneType(GeneratedsSuper):
             eol_ = ''
         if self.simpleTwoElementTwo is not None:
             showIndent(outfile, level, pretty_print)
-            outfile.write('<%ssimpleTwoElementTwo>%s</%ssimpleTwoElementTwo>%s' % (namespace_, self.gds_format_string(quote_xml(self.simpleTwoElementTwo).encode(ExternalEncoding), input_name='simpleTwoElementTwo'), namespace_, eol_))
+            outfile.write('<%ssimpleTwoElementTwo>%s</%ssimpleTwoElementTwo>%s' % (namespace_, self.gds_encode(self.gds_format_string(quote_xml(self.simpleTwoElementTwo), input_name='simpleTwoElementTwo')), namespace_, eol_))
     def build(self, node):
         already_processed = set()
         self.buildAttributes(node, node.attrib, already_processed)
diff --git a/tests/validate_simpletypes2_warnings.txt b/tests/validate_simpletypes2_warnings.txt
index 243afeda4eb08cad0f08d60449a78ce7b3f23e80..a6a01c2cddc0cf7e5ac14d496f654503641c0a56 100644
--- a/tests/validate_simpletypes2_warnings.txt
+++ b/tests/validate_simpletypes2_warnings.txt
@@ -1,34 +1,34 @@
-tests/validate_simpletypes2_sup.py:867: UserWarning: Value "2" does not match xsd minExclusive restriction on integer_range_1_st
+tests/validate_simpletypes2_sup.py:877: UserWarning: Value "2" does not match xsd minExclusive restriction on integer_range_1_st
   warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on integer_range_1_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:877: UserWarning: Value "mmaaa1234mnopzzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
+tests/validate_simpletypes2_sup.py:887: UserWarning: Value "mmaaa1234mnopzzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
   warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, ))
-tests/validate_simpletypes2_sup.py:890: UserWarning: Value "floatxx" does not match xsd enumeration restriction on token_enum_st
+tests/validate_simpletypes2_sup.py:900: UserWarning: Value "floatxx" does not match xsd enumeration restriction on token_enum_st
   warnings_.warn('Value "%(value)s" does not match xsd enumeration restriction on token_enum_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:897: UserWarning: Value "22" does not match xsd maxInclusive restriction on integer_range_incl_st
+tests/validate_simpletypes2_sup.py:907: UserWarning: Value "22" does not match xsd maxInclusive restriction on integer_range_incl_st
   warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on integer_range_incl_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:902: UserWarning: Value "-40" does not match xsd minExclusive restriction on integer_range_excl_st
+tests/validate_simpletypes2_sup.py:912: UserWarning: Value "-40" does not match xsd minExclusive restriction on integer_range_excl_st
   warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on integer_range_excl_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:911: UserWarning: Value "mno pqr" does not match xsd minLength restriction on min_max_length_st
+tests/validate_simpletypes2_sup.py:921: UserWarning: Value "mno pqr" does not match xsd minLength restriction on min_max_length_st
   warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on min_max_length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:916: UserWarning: Value "012345" does not match xsd length restriction on length_st
+tests/validate_simpletypes2_sup.py:926: UserWarning: Value "012345" does not match xsd length restriction on length_st
   warnings_.warn('Value "%(value)s" does not match xsd length restriction on length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:926: UserWarning: Value "0.2" does not match xsd minInclusive restriction on anonymous_float_valueType
+tests/validate_simpletypes2_sup.py:936: UserWarning: Value "0.2" does not match xsd minInclusive restriction on anonymous_float_valueType
   warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on anonymous_float_valueType' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:869: UserWarning: Value "9" does not match xsd maxExclusive restriction on integer_range_1_st
+tests/validate_simpletypes2_sup.py:879: UserWarning: Value "9" does not match xsd maxExclusive restriction on integer_range_1_st
   warnings_.warn('Value "%(value)s" does not match xsd maxExclusive restriction on integer_range_1_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:877: UserWarning: Value "aaa1234mnopzzzbcd" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
+tests/validate_simpletypes2_sup.py:887: UserWarning: Value "aaa1234mnopzzzbcd" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
   warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, ))
-tests/validate_simpletypes2_sup.py:895: UserWarning: Value "-50" does not match xsd minInclusive restriction on integer_range_incl_st
+tests/validate_simpletypes2_sup.py:905: UserWarning: Value "-50" does not match xsd minInclusive restriction on integer_range_incl_st
   warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on integer_range_incl_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:909: UserWarning: Value "asdf asdf asdf asdf asdf asdf" does not match xsd maxLength restriction on min_max_length_st
+tests/validate_simpletypes2_sup.py:919: UserWarning: Value "asdf asdf asdf asdf asdf asdf" does not match xsd maxLength restriction on min_max_length_st
   warnings_.warn('Value "%(value)s" does not match xsd maxLength restriction on min_max_length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:916: UserWarning: Value "01234567890" does not match xsd length restriction on length_st
+tests/validate_simpletypes2_sup.py:926: UserWarning: Value "01234567890" does not match xsd length restriction on length_st
   warnings_.warn('Value "%(value)s" does not match xsd length restriction on length_st' % {"value" : value.encode("utf-8")} )
-tests/validate_simpletypes2_sup.py:928: UserWarning: Value "6.6" does not match xsd maxInclusive restriction on anonymous_float_valueType
+tests/validate_simpletypes2_sup.py:938: UserWarning: Value "6.6" does not match xsd maxInclusive restriction on anonymous_float_valueType
   warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on anonymous_float_valueType' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:874: UserWarning: Value "aaa12zzz" does not match xsd minLength restriction on pattern_st
+tests/validate_simpletypes2_sup.py:884: UserWarning: Value "aaa12zzz" does not match xsd minLength restriction on pattern_st
   warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on pattern_st' % {"value" : value} )
-tests/validate_simpletypes2_sup.py:877: UserWarning: Value "aaa12zzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
+tests/validate_simpletypes2_sup.py:887: UserWarning: Value "aaa12zzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']]
   warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, ))
-tests/validate_simpletypes2_sup.py:1220: UserWarning: Value "pqrst" does not match xsd minLength restriction on simpleTwoElementTwoType
+tests/validate_simpletypes2_sup.py:1230: UserWarning: Value "pqrst" does not match xsd minLength restriction on simpleTwoElementTwoType
   warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on simpleTwoElementTwoType' % {"value" : value.encode("utf-8")} )
diff --git a/tutorial/generateds_tutorial.html b/tutorial/generateds_tutorial.html
index fc9f8490753bcf8d07467fbbdaa50a7cc2a6a003..22ee4cc6d17d10a278c72cb95db88ade998c1ca1 100644
--- a/tutorial/generateds_tutorial.html
+++ b/tutorial/generateds_tutorial.html
@@ -219,7 +219,7 @@ They are used by updateversion.py. -->
 <col class="field-name" />
 <col class="field-body" />
 <tbody valign="top">
-<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.18a</td>
+<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.19a</td>
 </tr>
 </tbody>
 </table>
@@ -228,7 +228,7 @@ They are used by updateversion.py. -->
 <col class="field-name" />
 <col class="field-body" />
 <tbody valign="top">
-<tr class="field"><th class="field-name">date:</th><td class="field-body">December 16, 2015</td>
+<tr class="field"><th class="field-name">date:</th><td class="field-body">February 08, 2016</td>
 </tr>
 </tbody>
 </table>
@@ -1210,7 +1210,7 @@ named <tt class="docutils literal">garden_api.py</tt>, you can create an instanc
 <div class="footer">
 <hr class="footer" />
 <a class="reference external" href="generateds_tutorial.txt">View document source</a>.
-Generated on: 2015-12-16 20:55 UTC.
+Generated on: 2016-02-08 18:02 UTC.
 Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
 
 </div>
diff --git a/tutorial/generateds_tutorial.zip b/tutorial/generateds_tutorial.zip
index 7c6fdd6a07d61e2adbceea14687cf1481b23ffa9..4d95f7ed52838130fc7596ee8b3d3f2c351bf979 100644
Binary files a/tutorial/generateds_tutorial.zip and b/tutorial/generateds_tutorial.zip differ