Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4036426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:13:18+00:00 2026-05-20T12:13:18+00:00

I have been trying to use XStreamMarshaller to generate XML output in my Java

  • 0

I have been trying to use XStreamMarshaller to generate XML output in my Java Spring project. The XML I am generating has CDATA values in the element text. I am manually creating this CDATA text in the command object like this:

 f.setText("<![CDATA[cdata-text]]>");

The XStreamMarshaller generated the element(text-data below is an alias) as:

<text-data><![CDATA[cdata-text]]></text-data>

The above XML display is as expected (Please ignore the back slash in the above element name: forum formatting). But when I do a View Source on the XML output generated I see this for the element: <text-data>&lt;![CDATA[cdata-text]]&gt;</text-data>.

Issue:

As you can see the less than and greater than characters have been replaced by &lt; and &gt; in the View Source. I need my client to read the source and identify CDATA section from the XML output which it will not in the above scenario.

Is there a way I can get the XStreamMarshaller to escape special characters in the text I provided?

I have set the encoding of the Marshaller to ISO-8859-1 but that does not work either. If the above cannot be done by XStreamMarshaller can you please suggest alternate marshallers/unmarshallers that can do this for me?

// Displaying my XML and View Source as suggested by Paŭlo Ebermann below:

XML View (as displayed in IE):

An invalid character was found in text content. Error processing resource 'http://localhost:8080/file-service-framework/fil...

Los t

View Source:

<service id="file-text"><text-data>&lt;![CDATA[
Los túneles a través de las montañas hacen más fácil viajar por carretera.
]]&gt;</text-data></service>

Thanks you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:13:18+00:00Added an answer on May 20, 2026 at 12:13 pm

    Generating CDATA sections is the task of your XML-generating library, not of its client. So you should simply have to write

    f.setText("cdata-text");
    

    and then the library can decide whether to use <![CDATA[…]]> or the &lt;-escaping for its contents. It should make no difference for the receiver.


    Edit:

    Looking at your output, it looks right (apart from the CDATA) – here you must work on your input, as said.

    If IE throws an error here, most probably you don’t have declared the right encoding.

    I don’t really know much about the Spring framework, but the encoding used by the Marshaller should be the same encoding as the encoding sent in either the HTTP header (Content-Type: ... ;charset=...) or the <?xml version="1.0" encoding="..." ?> XML prologue (these two should not differ, too).

    I would recommend UTF-8 as encoding everywhere, as this can represent all characters, not only the Latin-1 ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to use Spring in my Java EE projects and while
I have been trying to use querydsl in a project which is an osgi
I have been trying to use @Resource and @Service annotations in Spring as follows.
I have been trying to use UrlRewriter (Intelligencia.UrlRewriter.dll) in a test project. My rewrite
I have been trying to use date_format , however as far as I know,
I have been trying to use array_unique to remove duplicates from the search results
I have been trying to use routes.rb for creating a URL /similar-to-:product (where product
I have been trying to use the hibernate dialect for SQLite from http://code.google.com/p/hibernate-sqlite/ in
I have been trying to use/save the boolean value of a checkbox in other
I have been trying to use 3rd party tool called visiblox for rendering charts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.