> From: Dong Zhu >To: dkuhl...@rexx.com >Sent: Wednesday, December 19, 2012 1:02 AM >Subject: generateDS.py question > > FROM: Dong Zhu > > Hi Dave, > > May I bother you with a question regarding generateDS.py? > > I have been studying your article about the generateDS.py tool. > However, I still have a few questions unclear which I hope you can > help me. Thanks. > > Basically, here is what I want to do: > > I have a .xml file as a input data file. I need to parse the .xml > file and do some processes and output some results in other format. > The generateDS.py has possibilities of parsing the .xml into > instance tree. My special needs are these: > > 1. My .xml file and xsd file may change, and I don't want to > maintain manual codes that I have to write, the best way is to > let the generateDS update everything for me.
Dong - I do not have any easy answer to your questions, but here are some notes that might give you ideas. generateDS.py is a code generator, and so, like most code generators it requires that the code be *re*-generated when the specification from which the code is generated changes. So, when your XML Schema changes, you are likely to need to re-generated your module (with the -o command line option). *However*, you can minimize the consequences and difficulties caused from re-generation by keeping your application-specific code in a separate module and treating the generated module as a library. So, for example, if you generate a module as follows: $ generateDS.py -o myapplib.py myapp.xsd then your application specific module might contain this: import myapplib def parse(infile): root_object = myapplib.parse(infilename) o o o Note that by default, the parse function also exports (writes to stdout) the XML document. You can use the --silence command line option to generate parse functions that do not export. Or, you can either copy and modify the parse function or write your own. You might find it helpful to use the -s command line option and then look at the parse function in the resulting module. > > 2. I don't want to first to use the generated parse() to get the > instance tree and then do further walk through to make my own > process. Actually, all I want is to add a call to my own function > (which does some work for me) inside the generated method, > buildAttributes, so while parsing the .xml, it also creates the > results I need. But I don't want to manually redo the coding (ie > adding the function call inside the generated method) everything > when the generateDS.py reruns. Using the subclass method override > approach will not help, as I want to do my own task while doing > the parsing. > > Can you tell me how to add a specific function call inside the > generated method of a type class, or it is possible at all? Thanks > very much in advance! You seem to have considered using the technique that I would have suggested: specifically, using the -s command line option to generate a subclass module, then in that module override the buildChildren method in the classes you are interested in and either (1) call the buildChildren method in the superclass before or after your custom code or (2) copy the code from the superclass and insert your code in that copied code. But, you should consider that generateDS.py was intended to be used to create the entire tree of objects from the XML instance document and *then* enable the user's code to walk and process that tree. So, although your approach might be do-able, it's a bit non-standard from the generateDS.py point of view. You might also look at the calls to gds_validate_string, gds_validate_integer, etc in the generated buildChildren methods. Perhaps you would be able to add your custom code there. Or, if you need to add custom code that executes when a specific element type object is created, perhaps you could use a subclass file and add custom code to the appropriate constructor. Sorry for being so wordy. If you have suggestions on how to modify generateDS.py so as to provide the user with call back functions to support the customization of the generated methods that you need, I'd be interested in hearing then. Hope this is of some help. - Dave > > > Dong Zhu > Sr. SW Specialist -- Dave Kuhlman http://www.rexx.com/~dkuhlman ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users