
Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
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.