[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Dynamically generating Java 'wrapper' class for XML


java class to xml
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.

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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.