users@jaxb.java.net

Re: marshalling problem

From: Frank <fgeck_at_optonline.net>
Date: Wed, 15 Nov 2006 22:48:08 -0500

Well I added the string as a value of one of the elements of the larger
xml document/obj. How would I marshall only part of the object? Or
better yet. Now that I have a xml doc object with all the values I want
in all the fields how do I get it into a string? I thought what I did
was right (see below), but it creates those &lt; etc. Would this not be
the way to do it?
 public static String createMsgToSend (GetDocResponse msgObj)
{
        JAXBContext jc = JAXBContext.newInstance("csds.message");;
        StringWriter result = new StringWriter();
        Marshaller m = jc.createMarshaller();
        m.marshal(msgObj, result);
        msgStr = result.toString();
}

Kohsuke Kawaguchi wrote:

> Frank wrote:
>
>> I tried something that Dmitri eluted too to set the item element. I
>> did the following:
>>
>> csds.message.ObjectFactory objFact = new
>> csds.message.ObjectFactory();
>> csds.message.GetDocResponse gdr =
>> objFact.createGetDocResponse();
>> csds.message.GetDocResponse.Item item = new
>> csds.message.GetDocResponse.Item();
>> gdr.setTime(MeshUtil.setCurrentTime());
>> JAXBElement ele = new JAXBElement(new QName("",""), String.class,
>> ddsMsg);
>> item.setAny(ele);
>> gdr.setItem(item);
>>
>> The weird thing now is if you marshal this xml document out and print
>> it out all the "<" & ">" signs for the string ele have been replaced
>> with &lt; and &gt;. Any thoughts? Some encoding issue?
>
>
> That's as expected. '<' and '>' in XML needs to be escaped.
>
> If your string already contains XML, you don't need JAXB to marshal
> it, right?
>