Just noticed that I never sent this to the mailing list.

> From: Logan Owen
>Sent: Friday, February 24, 2012 10:13 AM


> Dave,
>
> First off, I want to say that I really appreciate the work you have
> done.  generateDS has made my life so much easier.
>

Logan -

Thanks for that comment.  It's rewarding to learn that generateDS.py
has been useful.  And, saving time for users is what this kind of
work is all about.

> One minor "short coming" that I have encountered, is the lack of
> ability to switch between pretty printing (newlines and indents) and
> "compressed" output when exporting generated XML.  I use generateDS
> in a distributed fashion to create a fairly high volume of XML
> messages sent through a message broker, and in production I would
> like to strip down the messages as much as possible.
>
> If this is something you also believe to be a useful feature, I will
> put together a patch and pass it on to you.

Yes, I also believe that would be a useful feature.  And, I agree
that generating XML transactions or structured data to be sent
across the wire for machine processing (as opposed to being read by
human eyes) is one class of use cases that generateDS.py should
support.  And, now that you mention it, I wish I had thought of it
myself.

And, a patch or bit of code would be great.  You're likely to steer
me in the direction of something that is more useful to you.

But, until I find the time to put that in, here are a couple of
alternatives, although I suspect you may have tried them already
yourself:

1. Replace the function showIndent in a generated module with a
function that does not write out whitespace.  You will still have
carriage returns, but eliminating the blanks will reduce the size
significantly.  If your app/script is importing the module
generated by generateDS.py, this is easy to do.  I've attached an
example that does it.

2. I'm not sure whether it would fit in with your tool chain and
its processing, but you could try post-processing your generated
output.  It would be reasonably easy to write a simple post
processing script yourself, in Python, of course, although it
might be fooled if your exported XML contains character content
that spans lines.  A better solution would be to use xmllint with
the --noblanks option.  Examples:

$ xmllint --noblanks -o out_doc.xml in_doc.xml
$ python my_gds_module.py in_doc.xml | xmllint --noblanks - | ...

The dash tells xmllint to read from stdin.  For info about
xmllint and xmlsoft, see: http://en.wikipedia.org/wiki/Libxml2

Hopes this helps.

- Dave



--


Dave Kuhlman
http://www.rexx.com/~dkuhlman



Dave,

That is great information, and initially all I did was edit indent().  I
was not aware of xmllint's capability to strip blanks, and while that
doesn't work for my current use case, it is helpful for future endeavors.

It actually wasn't too much work to add the pretty_print switch.  Attached
is a patch which implements the functionality.  Please let me know if there
are any issues you see with it.

Thanks,
Logan

>From b1fd8b39d15a6f9de7b18e1f01691c5ab74533dd Mon Sep 17 00:00:00 2001
From: lsowen <logan.owen@************.com>
Date: Fri, 24 Feb 2012 13:14:59 -0500
Subject: [PATCH] implement 'pretty print' functionality

---
 generateDS.py |  159 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 84 insertions(+), 75 deletions(-)

diff --git a/generateDS.py b/generateDS.py
index 3c97060..beb3f9e 100755
--- a/generateDS.py
+++ b/generateDS.py
@@ -1434,14 +1434,14 @@ def generateExportFn_1(wrt, child, name, namespace, fill):
         child_type == TimeType or \
         child_type == DateType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         # fixlist
         if (child.getSimpleType() in SimpleTypeDict and
             SimpleTypeDict[child.getSimpleType()].isListType()):
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_string(quote_xml(' '.join(self.%s)).encode(ExternalEncoding), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_string(quote_xml(' '.join(self.%s)).encode(ExternalEncoding), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_string(quote_xml(self.%s).encode(ExternalEncoding), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_string(quote_xml(self.%s).encode(ExternalEncoding), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type in IntegerType or \
@@ -1450,53 +1450,53 @@ def generateExportFn_1(wrt, child, name, namespace, fill):
         child_type == NegativeIntegerType or \
         child_type == NonNegativeIntegerType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_integer_list(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_integer_list(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_integer(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_integer(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type == BooleanType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_boolean_list(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_boolean_list(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_boolean(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_boolean(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type == FloatType or \
         child_type == DecimalType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_float_list(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_float_list(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_float(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_float(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type == DoubleType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_double_list(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_double_list(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_double(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_double(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     else:
         wrt("%s        if self.%s is not None:\n" % (fill, mappedName))
         # name_type_problem
         if False:        # name == child.getType():
-            s1 = "%s            self.%s.export(outfile, level, namespace_)\n" % \
+            s1 = "%s            self.%s.export(outfile, level, namespace_, pretty_print = pretty_print)\n" % \
                 (fill, mappedName)
         else:
-            s1 = "%s            self.%s.export(outfile, level, namespace_, name_='%s', )\n" % \
+            s1 = "%s            self.%s.export(outfile, level, namespace_, name_='%s', pretty_print = pretty_print)\n" % \
                 (fill, mappedName, name)
         wrt(s1)
 # end generateExportFn_1
@@ -1513,56 +1513,56 @@ def generateExportFn_2(wrt, child, name, namespace, fill):
         child_type == DateTimeType or \
         child_type == TimeType or \
         child_type == DateType:
-        wrt('%s        showIndent(outfile, level)\n' % fill)
-        wrt("%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_string(quote_xml(%s_).encode(ExternalEncoding), input_name='%s'), namespace_))\n" %
+        wrt('%s        showIndent(outfile, level, pretty_print)\n' % fill)
+        wrt("%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_string(quote_xml(%s_).encode(ExternalEncoding), 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 \
         child_type == NegativeIntegerType or \
         child_type == NonNegativeIntegerType:
-        wrt('%s        showIndent(outfile, level)\n' % fill)
+        wrt('%s        showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_integer_list(%s_, input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_integer_list(%s_, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         else:
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_integer(%s_, input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_integer(%s_, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         wrt(s1)
     elif child_type == BooleanType:
-        wrt('%s        showIndent(outfile, level)\n' % fill)
+        wrt('%s        showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_boolean_list(self.gds_str_lower(str(%s_)), input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_boolean_list(self.gds_str_lower(str(%s_)), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         else:
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_boolean(self.gds_str_lower(str(%s_)), input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_boolean(self.gds_str_lower(str(%s_)), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         wrt(s1)
     elif child_type == FloatType or \
         child_type == DecimalType:
-        wrt('%s        showIndent(outfile, level)\n' % fill)
+        wrt('%s        showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_float_list(%s_, input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_float_list(%s_, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         else:
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_float(%s_, input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_float(%s_, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         wrt(s1)
     elif child_type == DoubleType:
-        wrt('%s        showIndent(outfile, level)\n' % fill)
+        wrt('%s        showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_double_list(%s_, input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_double_list(%s_, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         else:
-            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_double(%s_, input_name='%s'), namespace_))\n" % \
+            s1 = "%s        outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_double(%s_, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, cleanName, name, )
         wrt(s1)
     else:
         # name_type_problem
         if False:        # name == child.getType():
-            s1 = "%s        %s_.export(outfile, level, namespace_)\n" % (fill, cleanName)
+            s1 = "%s        %s_.export(outfile, level, namespace_, pretty_print = pretty_print)\n" % (fill, cleanName)
         else:
-            s1 = "%s        %s_.export(outfile, level, namespace_, name_='%s')\n" % \
+            s1 = "%s        %s_.export(outfile, level, namespace_, name_='%s', pretty_print = pretty_print)\n" % \
                 (fill, cleanName, name)
         wrt(s1)
 # end generateExportFn_2
@@ -1579,14 +1579,14 @@ def generateExportFn_3(wrt, child, name, namespace, fill):
         child_type == TimeType or \
         child_type == DateType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         # fixlist
         if (child.getSimpleType() in SimpleTypeDict and
             SimpleTypeDict[child.getSimpleType()].isListType()):
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_string(quote_xml(' '.join(self.%s)).encode(ExternalEncoding), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_string(quote_xml(' '.join(self.%s)).encode(ExternalEncoding), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_string(quote_xml(self.%s).encode(ExternalEncoding), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_string(quote_xml(self.%s).encode(ExternalEncoding), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type in IntegerType or \
@@ -1595,53 +1595,53 @@ def generateExportFn_3(wrt, child, name, namespace, fill):
         child_type == NegativeIntegerType or \
         child_type == NonNegativeIntegerType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_integer_list(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_integer_list(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_integer(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_integer(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type == BooleanType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_boolean_list(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_boolean_list(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_boolean(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_boolean(self.gds_str_lower(str(self.%s)), input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name )
         wrt(s1)
     elif child_type == FloatType or \
         child_type == DecimalType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_float_list(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_float_list(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_float(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_float(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     elif child_type == DoubleType:
         wrt('%s        if self.%s is not None:\n' % (fill, mappedName, ))
-        wrt('%s            showIndent(outfile, level)\n' % fill)
+        wrt('%s            showIndent(outfile, level, pretty_print)\n' % fill)
         if child.isListType():
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_double_list(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_double_list(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         else:
-            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>\\n' %% (namespace_, self.gds_format_double(self.%s, input_name='%s'), namespace_))\n" % \
+            s1 = "%s            outfile.write('<%%s%s>%%s</%%s%s>%%s' %% (namespace_, self.gds_format_double(self.%s, input_name='%s'), namespace_, eol_))\n" % \
                 (fill, name, name, mappedName, name, )
         wrt(s1)
     else:
         wrt("%s        if self.%s is not None:\n" % (fill, mappedName))
         # name_type_problem
         if False:        # name == child.getType():
-            s1 = "%s            self.%s.export(outfile, level, namespace_)\n" % \
+            s1 = "%s            self.%s.export(outfile, level, namespace_, pretty_print = pretty_print)\n" % \
                 (fill, mappedName)
         else:
-            s1 = "%s            self.%s.export(outfile, level, namespace_, name_='%s')\n" % \
+            s1 = "%s            self.%s.export(outfile, level, namespace_, name_='%s', pretty_print = pretty_print)\n" % \
                 (fill, mappedName, name)
         wrt(s1)
 # end generateExportFn_3
@@ -1709,9 +1709,13 @@ def generateExportChildren(wrt, element, hasChildren, namespace):
         if element.isMixed():
             wrt('%sif not fromsubclass_:\n' % (fill, ))
             wrt("%s    for item_ in self.content_:\n" % (fill, ))
-            wrt("%s        item_.export(outfile, level, item_.name, namespace_)\n" % (
+            wrt("%s        item_.export(outfile, level, item_.name, namespace_, pretty_print = pretty_print)\n" % (
                 fill, ))
         else:
+            wrt('%sif pretty_print is True:\n' % (fill, ))
+            wrt("%s    eol_ = '\\n'\n" % (fill, ))
+            wrt('%selse:\n' % (fill, ))
+            wrt("%s    eol_ = ''\n" % (fill, ))
             any_type_child = None
             for child in element.getChildren():
                 unmappedName = child.getName()
@@ -1730,11 +1734,11 @@ def generateExportChildren(wrt, element, hasChildren, namespace):
                     if abstract_child and child.getMaxOccurs() > 1:
                         wrt("%sfor %s_ in self.get%s():\n" % (fill,
                             name, make_gs_name(name),))
-                        wrt("%s    %s_.export(outfile, level, namespace_, name_='%s')\n" % (
+                        wrt("%s    %s_.export(outfile, level, namespace_, name_='%s', pretty_print = pretty_print)\n" % (
                             fill, name, name, ))
                     elif abstract_child:
                         wrt("%sif self.%s is not None:\n" % (fill, name, ))
-                        wrt("%s    self.%s.export(outfile, level, namespace_, name_='%s')\n" % (
+                        wrt("%s    self.%s.export(outfile, level, namespace_, name_='%s', pretty_print = pretty_print)\n" % (
                             fill, name, name, ))
                     elif child.getMaxOccurs() > 1:
                         generateExportFn_2(wrt, child, unmappedName, namespace, '    ')
@@ -1746,10 +1750,10 @@ def generateExportChildren(wrt, element, hasChildren, namespace):
             if any_type_child is not None:
                 if any_type_child.getMaxOccurs() > 1:
                     wrt('        for obj_ in self.anytypeobjs_:\n')
-                    wrt("            obj_.export(outfile, level, namespace_)\n")
+                    wrt("            obj_.export(outfile, level, namespace_, pretty_print = pretty_print)\n")
                 else:
                     wrt('        if self.anytypeobjs_ is not None:\n')
-                    wrt("            self.anytypeobjs_.export(outfile, level, namespace_)\n")
+                    wrt("            self.anytypeobjs_.export(outfile, level, namespace_, pretty_print = pretty_print)\n")
     return hasChildren
 # end generateExportChildren
 
@@ -1780,9 +1784,13 @@ def generateExportFn(wrt, prefix, element, namespace):
     childCount = countChildren(element, 0)
     name = element.getName()
     base = element.getBase()
-    wrt("    def export(self, outfile, level, namespace_='%s', name_='%s', namespacedef_=''):\n" % \
+    wrt("    def export(self, outfile, level, namespace_='%s', name_='%s', namespacedef_='', pretty_print=True):\n" % \
         (namespace, name, ))
-    wrt('        showIndent(outfile, level)\n')
+    wrt('        if pretty_print is True:\n')
+    wrt("            eol_ = '\\n'\n")
+    wrt('        else:\n')
+    wrt("            eol_ = ''\n")
+    wrt('        showIndent(outfile, level, pretty_print)\n')
     wrt("        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))\n")
     wrt("        already_processed = []\n")
     wrt("        self.exportAttributes(outfile, level, already_processed, namespace_, name_='%s')\n" % \
@@ -1795,8 +1803,8 @@ def generateExportFn(wrt, prefix, element, namespace):
             pass
     if childCount == 0 and element.isMixed():
         wrt("        outfile.write('>')\n")
-        wrt("        self.exportChildren(outfile, level + 1, namespace_, name_)\n")
-        wrt("        outfile.write('</%s%s>\\n' % (namespace_, name_))\n")
+        wrt("        self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print = pretty_print)\n")
+        wrt("        outfile.write('</%s%s>%s' % (namespace_, name_, eol_))\n")
     else:
         wrt("        if self.hasContent_():\n")
         # Added to keep value on the same line as the tag no children.
@@ -1805,14 +1813,14 @@ def generateExportFn(wrt, prefix, element, namespace):
             if not element.isMixed():
                 wrt("            outfile.write(str(self.valueOf_).encode(ExternalEncoding))\n")
         else:
-            wrt("            outfile.write('>\\n')\n")
-        wrt("            self.exportChildren(outfile, level + 1, namespace_, name_)\n")
+            wrt("            outfile.write('>%s' % (eol_, ))\n")
+        wrt("            self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print = pretty_print)\n")
         # Put a condition on the indent to require children.
         if childCount != 0:
-            wrt('            showIndent(outfile, level)\n')
-        wrt("            outfile.write('</%s%s>\\n' % (namespace_, name_))\n")
+            wrt('            showIndent(outfile, level, pretty_print)\n')
+        wrt("            outfile.write('</%s%s>%s' % (namespace_, name_, eol_))\n")
         wrt("        else:\n")
-        wrt("            outfile.write('/>\\n')\n")
+        wrt("            outfile.write('/>%s' % (eol_, ))\n")
     wrt("    def exportAttributes(self, outfile, level, already_processed, namespace_='%s', name_='%s'):\n" % \
         (namespace, name, ))
     hasAttributes = 0
@@ -1853,7 +1861,7 @@ def generateExportFn(wrt, prefix, element, namespace):
     hasAttributes += generateExportAttributes(wrt, element, hasAttributes)
     if hasAttributes == 0:
         wrt("        pass\n")
-    wrt("    def exportChildren(self, outfile, level, namespace_='%s', name_='%s', fromsubclass_=False):\n" % \
+    wrt("    def exportChildren(self, outfile, level, namespace_='%s', name_='%s', fromsubclass_=False, pretty_print = True):\n" % \
         (namespace, name, ))
     hasChildren = 0
     # Generate call to exportChildren in the superclass only if it is
@@ -3452,9 +3460,10 @@ Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')
 # Support/utility functions.
 #
 
-def showIndent(outfile, level):
-    for idx in range(level):
-        outfile.write('    ')
+def showIndent(outfile, level, pretty_print = True):
+    if pretty_print is True:
+        for idx in range(level):
+            outfile.write('    ')
 
 def quote_xml(inStr):
     if not inStr:
@@ -3559,7 +3568,7 @@ class MixedContainer:
         return self.value
     def getName(self):
         return self.name
-    def export(self, outfile, level, name, namespace):
+    def export(self, outfile, level, name, namespace, pretty_print = True):
         if self.category == MixedContainer.CategoryText:
             # Prevent exporting empty content as empty lines.
             if self.value.strip(): 
@@ -3567,7 +3576,7 @@ class MixedContainer:
         elif self.category == MixedContainer.CategorySimple:
             self.exportSimple(outfile, level, name)
         else:    # category == MixedContainer.CategoryComplex
-            self.value.export(outfile, level, namespace,name)
+            self.value.export(outfile, level, namespace, name, pretty_print)
     def exportSimple(self, outfile, level, name):
         if self.content_type == MixedContainer.TypeString:
             outfile.write('<%%s>%%s</%%s>' %% (self.name, self.value, self.name))
@@ -3579,21 +3588,21 @@ class MixedContainer:
             outfile.write('<%%s>%%f</%%s>' %% (self.name, self.value, self.name))
         elif self.content_type == MixedContainer.TypeDouble:
             outfile.write('<%%s>%%g</%%s>' %% (self.name, self.value, self.name))
-    def exportLiteral(self, outfile, level, name):
+    def exportLiteral(self, outfile, level, name, pretty_print):
         if self.category == MixedContainer.CategoryText:
-            showIndent(outfile, level)
+            showIndent(outfile, level, pretty_print)
             outfile.write('model_.MixedContainer(%%d, %%d, "%%s", "%%s"),\\n' %% \\
                 (self.category, self.content_type, self.name, self.value))
         elif self.category == MixedContainer.CategorySimple:
-            showIndent(outfile, level)
+            showIndent(outfile, level, pretty_print)
             outfile.write('model_.MixedContainer(%%d, %%d, "%%s", "%%s"),\\n' %% \\
                 (self.category, self.content_type, self.name, self.value))
         else:    # category == MixedContainer.CategoryComplex
-            showIndent(outfile, level)
+            showIndent(outfile, level, pretty_print)
             outfile.write('model_.MixedContainer(%%d, %%d, "%%s",\\n' %% \\
                 (self.category, self.content_type, self.name,))
             self.value.exportLiteral(outfile, level + 1)
-            showIndent(outfile, level)
+            showIndent(outfile, level, pretty_print)
             outfile.write(')\\n')
 
 
-- 
1.7.1

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to