On Sun 22 Sep 2013 09:25:48 AM PDT, George David wrote: > Hi Dave, > > I've had a lot of trouble with generateDS not creating valid XML for the > XSDs I use. The biggest problem I had was getting generateDS to create XML > with valid namespaces. After looking at the code and running the debugger, > I believe the problem stems from the fact that generateDS creates a single > root with all the included/imported XSDs appended to it. This is done in > process_includes.prep_schema_doc(). >
George, Right. I suspect that what you are finding is that those separate schemas use different namespaces, and if we combine them all we generate Python classes in a single namespace, and we have a mess. > After many tests I decided the best way to fix this was to avoid this > altogether and process each imported XSD independently. As a result of this > change it appeared necessary to have generateDS create a python module for > each XSD (or at least it was easier to do this). Sounds like an approach that is hopeful, if you can work with all those generated files. And, if you have not done so already, you might put all those generated files into a single Python package (a directory containing a file named __init__.py) and in the __init__.py file, import each of your generated files, so that when someone imports the package/directoryitself, those generated modules will be available at the top level. I'm thinking about this because this subject (Python packages) is one that I covered in the beginning Python class I taught last week. I'm assuming that you are using the --no-process-includes command line option, right? > Having one python module > per XSD is better for me anyways as this is how we do it for our java code. You're in a Java shop. Then, if you have not already done so, you should at least look at XMLBeans: https://en.wikipedia.org/wiki/XMLBeans http://xmlbeans.apache.org/ And, maybe the JAXB too: https://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding Roughly speaking, it does for Java what generateDS.py does for Python. And, although I have not tried it for several years, back when I did, the code and the jar files generated by one or perhaps both of the above were usable with Jython. > > I now have a working version of this that works with the 100 or so XSD > files I use. Wow. Super. > I attempted to make this change without disrupting how > genereateDS works otherwise. In a previous email you mentioned there are > unit tests. Would you explain how to run these? Once I get those to pass > I'll check these in to my repo and submit a pull request. > To run the unit tests, do this: $ cd generateDS/tests $ python test.py But, it's likely that many of the unit tests will fail. What most of them do is generate the Python code, and then do a (diff) comparison with the code generated by a previous version of generateDS.py. So, any change that you make which causes a difference in the code generated is likely to make some unit tests fail. When that happens, I run diff on the previous and current code generated, then do a visual inspection of the differences, and if I can convince myself that any differences are really what I want, then I copy the new generated file on top of (replace) the previous file. Since I use both the -o and the -s command line flags to generate superclasses and subclasses, and these output files have names like this (in the generateDS/tests directory): xxxx1_sup.py -- old superclass file xxxx2_sup.py -- new superclass file xxxx1_sub.py -- old subclass file xxxx2_sub.py -- new subclass file If you want to add a new unit test, in tests/test.py, take a look at function test_018_simpletypes_other, if you want to compare the generated Python bindings and take a look at test_014_xsi_type, if you want to compare the exported XML file. Hope this helps a bit. Let me know if I can answer any more questions. Dave -- Dave Kuhlman http://www.davekuhlman.org ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users