pg has asked for the wisdom of the Perl Monks concerning the following question:

I need some suggestions from monks. I will soon work on a project, which is XML related, and have to deal with lots of different XML Schemas. I know we have SAX, DOM and all those kind of things, and I know we have lots of modules from active Perl, and also CPAN that deals with XML. However all of those have a common problem, that the development cycle is too long, and I am looking at something a layer above.

I will do the whole project in an OO style. What I am looking at now, is a (or a set of) module that support such a methodology: it takes the XML Schemas, and generate the Perl OO classes, which can contain the layered-image of the XML data, and also generates all the accessors, at least the restriction checking and all the setters/getters (In Perl, most people like to combine the setter and getter, if you use it without parms, it is a getter, otherwise it is a setter). Then SAX or DOM will be used upon the XML files as parser, and I can take the parsed data and store the parsed data in those generated classes, and access them thru those generated methods (well, I expect that I have to manually add some other methods on top, but that is fine).

This will, I believe, largely reduce the development effort.

I don’t think there is any existing Perl module does this, but I am looking at fellow monks to share your suggestions and ideas.
  • Comment on automated conversion from XML Schema to Perl OO

Replies are listed 'Best First'.
Re: automated conversion from XML Schema to Perl OO
by chromatic (Archbishop) on Nov 19, 2002 at 21:35 UTC

    The major difficulty I see is that a schema does not encapsulate sufficient semantic data that you can construct a given object appropriately. This is widely considered to be a problem with computers in general. It doesn't mean that your job is impossible, nor that it is not worth pursuing. It does mean that you probably won't create objects for arbitrarily complex schemas that won't need some human touches.

Re: automated conversion from XML Schema to Perl OO
by panix (Monk) on Nov 19, 2002 at 22:41 UTC
    One of the contractors I work with has a sourceforge project that does this - xml to java/perl/etc. It's available at http://sourceforge.net/projects/sysmod.

    The perl it's generating doesn't look like it's handling inheritence properly, and it's not generating DBI calls like it does for java, but you may still find it usable/a place to start.

Re: automated conversion from XML Schema to Perl OO
by gjb (Vicar) on Nov 19, 2002 at 21:47 UTC

    You may want to have a look at the JAXB project (Java Architecture for XML Binding). This is a SUN project that seems to be similar to what you have in mind. Note that you have to register in order to access the JDC (Java Developers Connection) site.

    Hope this helps, -gjb-

Re: automated conversion from XML Schema to Perl OO
by Anonymous Monk on May 30, 2017 at 11:54 UTC
    One of the modules that I have seen being used is XML::Pastor. You can use this to generate perl modules based on the schema which has the necessary accessors and use it while parsing the XML.