OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Dynamically generating Java 'wrapper' class for XML

[ Lists Home | Date Index | Thread Index ]

Bob Foster wrote:

> Isn't there a problem with the example? The document has two asset 
> elements within the quote element (probably could have any number), 
> yet your hypothetical getAssetName() method seems to assume only one 
> asset.
> Other than that, your general approach (generate with JAXB, use 
> introspection over the generated classes to produce a wrapper class) 
> is probably ok, just not as simple as you may suppose. First thing to 
> do is generate some code with JAXB from your schema and read the 
> generated code.

I have been using JAXB and before that Castor XML for generating Java 
Binding classes from XML Schema and using them to reliably process and 
generate XML for several years in the freebXML Registry open source 
project [1]. I have found XML Data Binding in general and JAXB in 
particular to be a huge time saving and the generated code to be solid 
and reliable. I have been told by some that they prefer using SAX/DOM 
the old fashioned way for XML processing for performance reasons. I have 
not found any practical issues with performance using a JAXB based 
approached. I highly recommend JAXB for XML processing and generation.

I work for Sun but the opinions expressed are my own and reflect 
personal open source development experience.

> Bob Foster
> 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:)
>> Regards,
>> Oswald
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> The list archives are at http://lists.xml.org/archives/xml-dev/
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>



News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS