Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Castor Mapping with XSLT

Reply
Thread Tools

Castor Mapping with XSLT

 
 
wlaver@gmail.com
Guest
Posts: n/a
 
      08-21-2006
I am marshalling a java object to xml. I would like to include a
stylesheet declaration in my castor mapping xml file.

My mapping file looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="main-summary.xsl"?>
<mapping>
content ...
</mapping>

When I marshal the java object, the xml file is created, but the
<?xml-stylesheet line is dropped and no error is reported.

Does anyone know why this happens, or another way that I can output the
xml file with a stylesheet declared?

Thanks,

Mike

 
Reply With Quote
 
 
 
 
Daniel Dyer
Guest
Posts: n/a
 
      08-21-2006
On Mon, 21 Aug 2006 21:37:07 +0100, <(E-Mail Removed)> wrote:

> I am marshalling a java object to xml. I would like to include a
> stylesheet declaration in my castor mapping xml file.
>
> My mapping file looks as follows:
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl" href="main-summary.xsl"?>
> <mapping>
> content ...
> </mapping>
>
> When I marshal the java object, the xml file is created, but the
> <?xml-stylesheet line is dropped and no error is reported.
>
> Does anyone know why this happens, or another way that I can output the
> xml file with a stylesheet declared?


It's because your stylesheet line applies to the mapping file, not the
file output by Castor. Take a look at the addProcessingInstruction of the
Marshaller class
(http://www.castor.org/api/org/exolab...va.lang.String,
java.lang.String))

You need to do something like this:

marshaller.addProcessingInstruction("xml-stylesheet",
"href=\"main-summary.xsl\" type=\"text/xsl\"");

Dan.

P.S. After trying JiBX (http://www.jibx.org), I doubt I will use Castor
XML again. The mapping files are more elegant, my XML processing was 9
times faster and I had more control over the mapped classes (didn't have
to expose public setters and have non-final fields).

--
Daniel Dyer
http://www.dandyer.co.uk
 
Reply With Quote
 
 
 
 
mbuckley
Guest
Posts: n/a
 
      08-21-2006
Thanks Dan, that worked for me.

I will take a look at JiBX, as I have similar complaints about castors
mapping files.

Cheers,

Mike

Daniel Dyer wrote:
> On Mon, 21 Aug 2006 21:37:07 +0100, <(E-Mail Removed)> wrote:
>
> > I am marshalling a java object to xml. I would like to include a
> > stylesheet declaration in my castor mapping xml file.
> >
> > My mapping file looks as follows:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <?xml-stylesheet type="text/xsl" href="main-summary.xsl"?>
> > <mapping>
> > content ...
> > </mapping>
> >
> > When I marshal the java object, the xml file is created, but the
> > <?xml-stylesheet line is dropped and no error is reported.
> >
> > Does anyone know why this happens, or another way that I can output the
> > xml file with a stylesheet declared?

>
> It's because your stylesheet line applies to the mapping file, not the
> file output by Castor. Take a look at the addProcessingInstruction of the
> Marshaller class
> (http://www.castor.org/api/org/exolab...va.lang.String,
> java.lang.String))
>
> You need to do something like this:
>
> marshaller.addProcessingInstruction("xml-stylesheet",
> "href=\"main-summary.xsl\" type=\"text/xsl\"");
>
> Dan.
>
> P.S. After trying JiBX (http://www.jibx.org), I doubt I will use Castor
> XML again. The mapping files are more elegant, my XML processing was 9
> times faster and I had more control over the mapped classes (didn't have
> to expose public setters and have non-final fields).
>
> --
> Daniel Dyer
> http://www.dandyer.co.uk


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Castor]How to install Castor properly? Sam Hwang Java 0 04-26-2005 08:54 AM
Castor and collections: mapping file needed for unmarshalling? Chris XML 0 02-26-2004 01:59 PM
Castor and collections: mapping file needed for unmarshalling? Chris Java 0 02-26-2004 01:59 PM
Castor File Mapping ??? Ajay Singh Tomar Java 0 01-19-2004 09:37 AM
Object relational mapping with Castor D L.Strang Java 0 07-09-2003 03:01 PM



Advertisments