Next in thread →
Next in month →
Re: [xml-dev] Dynamically generating Java 'wrapper' class for XML
As a general rule, XML data binding products require the structure of the XML schema to match the structure of the generated classes. In your case, this would mean separate classes for quote and asset, which is not what you're asking for. Some products have mapping languages that allow you to modify how the classes are generated. The language in JiBX [1] is liberal enough that the structures don't have to match, so this might work for you (modulo the aforementioned problem that there are two asset names per class). JAXB also has a mapping language, but I don't know if it is liberal enough to handle this sort of thing. -- Ron [1] http://jibx.sourceforge.net/ Oswald Campesato wrote: > Hello, everyone: > > I need to dynamically generate a Java class that > will expose a methods for each element of a given > XML document. > > For example, suppose I have this XML document: > --------------------- > <quote> > <name>Oracle</name> > <loc>RWS</loc> > <asset> > <name>ST</name> > <loc>400</loc> > </asset> > <asset> > <name>CRM</name> > <location>600</location> > </asset> > .... > </quote> > --------------------- > > I need to generate a Java class with the following: > > public String getQuoteName() > { > quote.getName(); > } > > public String getAssetName() > { > quote.getAsset().getName(); > } > > public String getAssetLoc() > { > quote.getAsset().getLoc(); > } > .... > > where 'quote' is a JAXB-based instance of a > Java class corresponds to an unmarshalled > instance of the preceding XML document. > > The Java wrapper class needs to be generated > each time an XSD is modified, and it will be > invoked by a third-party product in order to > modify the contents of an XML document. > > I was thinking of using JAXB 2.0 to generate the > Java binding classes associated with an XSD, and > then use introspection to determine the existing > methods, and then iterate over those methods to > generate the Java wrapper class. > > Does this seem like a good approach, or is there > a more 'elegant' approach? Hopefully this makes > sense:)
Next in thread →
Next in month →