Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

XML generator

Thread view: 
vsingr - 30 Nov 2005 14:47 GMT
Friends
Does anyone know any open source which can take a XML template and a
bunch of Java Objects and spit out an XML which follows the template? I
tried this product called axt but for some reason i get a
"java.lang.UnsupportedClassVersionError:" in my main class. Any help in
this regard would be greatly appreciated.
Thanks
Sriram
cbroussard@liquiddatainc.com - 30 Nov 2005 18:34 GMT
there are a lot out there.. two that i've used is...

jax-b (part of java web services package) & xml beans (jakarta project)

hope that helps

http://www.binaryfrost.com
vsingr - 30 Nov 2005 18:50 GMT
thanks for the response, but Jax-b takes a schema or an XMl my
requirements is that I have java Objects which needs to become an XML
which follows the template specified. inshort of the template changes
at a future date the XML should be generated accordingly and
interesting part is that I dont have the luxury of using schema or a
DTD.
Chris Smith - 30 Nov 2005 20:09 GMT
> thanks for the response, but Jax-b takes a schema or an XMl my
> requirements is that I have java Objects which needs to become an XML
> which follows the template specified. inshort of the template changes
> at a future date the XML should be generated accordingly and
> interesting part is that I dont have the luxury of using schema or a
> DTD.

What format is the template?

If you have a choice, then use JAXB anyway, and make the template an
XSLT document to transform to the desired format.  If you don't have a
choice, then obviously it's a waste of anyone's time to answer you until
you tell us what template format you need to use.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

vsingr - 30 Nov 2005 20:12 GMT
My template would be in XML format. I need some kind of marshalling
mechanism which would actually take the java objects and convert them
into a XML based on the XML template. I can have some repeating and
some non repeating elements in the process. This template is subject to
change hence I need the flexibility to feed a different template and
get the output.
Chris Smith - 30 Nov 2005 22:08 GMT
> My template would be in XML format. I need some kind of marshalling
> mechanism which would actually take the java objects and convert them
> into a XML based on the XML template. I can have some repeating and
> some non repeating elements in the process. This template is subject to
> change hence I need the flexibility to feed a different template and
> get the output.

So far, you've said nothing to prevent your using XSLT for the template.  
An XSLT document is an XML file.  Seems like you're all set.

On the other hand, it sounds like you actually think you're being
specific when you say that your template will be an XML file.  In
reality, XML is *not* a file format.  It's a set of rules for defining a
file format.  XSLT is an example of a file format based on XML.  XSLT is
a particularly appropriate example, since its entire purpose is to
describe how to take data and build other XML documents from it.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

vsingr - 01 Dec 2005 14:31 GMT
Correct me if I am wrong.
Doesnt XSLT require an XML document as an input? I only have Java beans
here. I need XML as an output.

Am I thinking totally along wrong lines.
ThanksSriram
asaguden - 07 Dec 2005 16:54 GMT
> Correct me if I am wrong. Doesnt XSLT require an XML document as an input?
- You are not wrong.

I only have Java beans here. I need XML as an output.
- Only Beans? One representation of the bean could be XML (
MyBean.toXML() ) or you can use package XStream to externally create
XML DOM from your Java objects.

> Am I thinking totally along wrong lines.
- I think an example of your 'template' would give us a better
understanding...

> ThanksSriram
- asaguden
vsingr - 08 Dec 2005 14:58 GMT
Well,
the template would be something like this
<Student>
    <first_name></first_name>
    <last_name></last_name>
    <email></email>
      <course></course>
</Student>

Now for data in these tags i need a way to fill them in. I found this
product called velocity from apache which seems to be doing that. For
starters it uses JSTLU like expression language which will work fine in
a web environment with POJO being passed around in session or request
objects.
How ever i have run into a new issue here.
My requirement is that i use it in a non-HTTP environment. Is there a
way i can pass around POJO to JSTL or an experession language variable
without using the session or request objects? Can someone throw light
on this please
In the above template say the student is a part of multiple courses
asaguden - 09 Dec 2005 09:21 GMT
If I understand you correctly, then I have done just this.I used XML,
XSL and DTD with Java to accomplish this.
-----------------------------------------
Here is my problem:
- We have data, in POJOs
- We need to output the data in XML format, according to a DTD
- The recipient of the XML may not have access to the Web, therefore
  we need an internal DTD
- DOM2 could NOT set the DTD internally, only read it.

..and solution:
- I have an XSL file that is my template, it contains both the DTD and
the transform
- I have a java file that creates the XML DOM from a Bean object
(POJO)
- I transform the XSL and DOM into the resulting XML:
<code>
transformer = XslTransformation.getInstance().getTransformer(
"xsl-file" );
transformer.transform(new DOMSource( java-dom ), new StreamResult(os));
</code>
- The resulting XML is validated against the internal DTD

xsl file:
<code>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
   <xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/>
   <xsl:template match="RootElement">
       <xsl:text disable-output-escaping="yes">
           <![CDATA[
       <!DOCTYPE RootElement [
           <!ELEMENT OtherElement EMPTY>
           <!ATTLIST OtherElement DATATYPE NMTOKEN #FIXED "BOOLEAN"
VALUE NMTOKEN #REQUIRED>
           <!ELEMENT RootElement (List+)>
           <!ELEMENT List>
       ]>
       ]]>
       </xsl:text>

       <RootElement>
           <xsl:apply-templates select="List"/>
       </RootElement>

   </xsl:template>

   <xsl:template match="List">
       <List>
    ...more elements and attlists..
       </List>
   </xsl:template>

</xsl:stylesheet>
</code>
--------------------------------------
I think I know what you want, and I hope any of this helps.
asaguden
Chris Uppal - 01 Dec 2005 14:58 GMT
> My template would be in XML format. I need some kind of marshalling
> mechanism which would actually take the java objects and convert them
> into a XML based on the XML template.

It sounds to me as if your template is not an /XML/ template as such.  It's
just a file (or string) which "happens" to resemble XML enough that when the
template engine processes your object it emits valid XML.  If the template were
changed so that it, say, resembled PostScript, then the same processing would
produce PostScript output.

If I'm right, then you might have better luck looking for template engines in
general, rather than concentrating on XML.  Searching for:
   "template engine" java
shows lots of promising looking hits.

   -- chris
vsingr - 01 Dec 2005 15:29 GMT
i would say that you are partially right. In the sense that my template
can change but the poutput always remains XML The template format which
is XML like can also change not the format it self but the internal
elements and such. like for example I could be forced to replace an
existing element with a different name or introduce a new one.
Roedy Green - 30 Nov 2005 18:45 GMT
>UnsupportedClassVersionError

see
http://mindprod.com/jgloss/runerrormessages.html#UNSUPPORTEDCLASSVERSIONERROR
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

asaguden - 01 Dec 2005 09:40 GMT
How come u cant use DTD?

I have done a similar exercise with DTD;
- create XSL file with internal DTD ( your template )
- read the XSL file ( Transformer )
- create DOM document in Java ( from your Java objects)
- use transform on DOM to get resulting XML

In this solution the DOM won't rewrite itself. But if you change the
XSL it will fail to validate the DOM.

More:
I have no personal experience of this pacakge, but I think it has a
lot of usable features: http://xstream.codehaus.org/

Good luck.
-----------------------------------------------------------------

> Friends
> Does anyone know any open source which can take a XML template and a
[quoted text clipped - 4 lines]
> Thanks
> Sriram


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.