Hi Bo,
This is quite normal in fact, when you do it like that the tags in the <body> decomes part of your xml and if you were validating against a DTD or a Schema there are some chances that it would not validate because the <body> element would certainly be of CDATA type.
What you have to do is to precise that the contained string is not XML.
You can do it in two maners;
- Or you are using entities and this will give you the following:
<body>
<p>The body of the <b>news</b></p>
</body>
Castor will resolve the entities when unmarshalling and you will get the correct string
- Or you use a CDATA section (http://www.w3.org/TR/2000/REC-xml-20001006#sec-cdata-sect), like that:
<body><![CDATA[
<p>The body of the <b>news</b></p>
]]></body>
It is more human-readable, but I think that if you marshall it again with Castor you will finally get the "entities" version
Regards,
Claude
> -----Original Message-----
> From: Bo Gundersen [mailto:[EMAIL PROTECTED]]
> Sent: 21 February 2003 07:34
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] Howto map a whole XML element to a
> single String?
>
>
> Hi,
>
> I have been puzzeling with this problem for some time, and I simply
> cannot get it to work.
>
> My xml is something like this:
> <news>
> <title>Some news</title>
> <body>
> <p>The body of the <b>news</b></p>
> </body>
> <author>Me, Myself and I</author>
> <date>2003-02-21</date>
> </news>
>
> My problem is that I would like to map the entire body tag to
> a single
> String on the object, this is no problem as long as the body does not
> contain any tags, but if it contain tags these are not passed
> as part of
> the body string.
>
> My current castorMapping.xml is as follows:
> <class name="dk.aub.webservice.news.om.News">
> <map-to xml="news"/>
> <field name="id" type="integer" required="false"/>
> <field name="title" type="string" required="false"/>
> <field name="body" type="string"
> handler="dk.aub.webservice.BodyHandler">
> <bind-xml name="body" node="element"/>
> </field>
> <field name="author" type="string" required="false"/>
> <field name="date" type="string"
> handler="dk.aub.webservice.DateHandler" >
> <bind-xml name="date" node="element"/>
> </field>
> </class>
>
> And my body handler is as follows:
> public class BodyHandler implements FieldHandler {
> public Object getValue(Object o) throws IllegalStateException {
> return ((News)o).getBody();
> }
>
> public void setValue(Object o, Object o1)
> throws IllegalStateException, IllegalArgumentException {
> News n = (News)o;
> n.setBody((String)o1);
> }
>
> public void resetValue(Object o)
> throws IllegalStateException, IllegalArgumentException {
> System.err.println("XX resetValue(" + o + ")");
> }
>
> public void checkValidity(Object o)
> throws ValidityException, IllegalStateException {
> System.err.println("XX checkValidity(" + o + ")");
> }
>
> public Object newInstance(Object o)
> throws IllegalStateException {
> System.err.println("XX newInstance(" + o + ")");
> return new String();
> }
> }
>
> Does anyone has an idea on how to do this?
> Thanks in advance.
>
> --
> Bo Gundersen
> DBA/Software Developer
> M.Sc.CS.
> www.atira.dk
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
__________________________________________________________________________
· This email and any files transmitted with it are CONFIDENTIAL and intended
solely for the use of the individual or entity to which they are addressed.
· Any unauthorized copying, disclosure, or distribution of the material within
this email is strictly forbidden.
· Any views or opinions presented within this e-mail are solely those of the
author and do not necessarily represent those of Odyssey Asset Management
Systems SA unless otherwise specifically stated.
· An electronic message is not binding on its sender. Any message referring to
a binding engagement must be confirmed in writing and duly signed.
· If you have received this email in error, please notify the sender immediately
and delete the original.
