& is a correct way to represent an ampersand in syntactically valid xml, a single & is not.
you have to escape the ampersand somehow; otherwise, it has to begin an entity.
When you unmarshal the xml text the resulting String will contain the &. Or if you use an xml parser to create a DOM or process the xml using xslt (which uses an xml parser) to produce non-xml the value will contain the desired character


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 19, 2005 5:01 PM
To: [email protected]
Subject: [castor-user] XML message contains &
Importance: High

While generating XML using castor marshal method; if data object contains ‘&‘ character; it is getting converted into &

How to avoid this? I want the same character  back in XML message. Please help.

 

Sample code:

StringWriter writer = new StringWriter();

String xml = null;

dpMessage.marshal(writer);

xml = writer.toString();

 

 

Input data:

ELLSWORTH & GRAHAM BOOK SHOP Accounts/47-3423230

 

Output xml:

<DPMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DPMessage">

   <body>

            <detailedSummary>

                <dsCompanyName_TIN>ELLSWORTH &amp; GRAHAM BOOK SHOP Accounts/47-3423230</dsCompanyName_TIN>

            </detailedSummary>

    </body>

</DPMessage>

 

 

Thanks,

Pravin

 

Reply via email to