When i do for example:

Xml field = new Xml("Field", "KOSTENTRÄGER");  // Ä

"&" is converted to "& amp;", when i convert the xml object to string.

It's look for example like this:

<FIELD>KOSTENTR&amp;#196;GER</FIELD>

How can i avoid this?

asked 10.01.2017 at 12:42

tiago's gravatar image

tiago
(suspended)
accept rate: 0%

edited 10.01.2017 at 14:35


The problem with '&' in an XML file is, that everything after the '&' until the next semicolon will be encoded. A single '&' without a semicolon (or with a meaningless term between them) would lead to an invalid XML file. To avoid this problem, the serializer just converts every '&' to '& amp;', even if it stands already for an encoded character (see http://stackoverflow.com/questions/730133/invalid-characters-in-xml).

You could just replace the encoded parts with the character itself ("KOSTENTRÄGER" instead of "KOSTENTR&#196 ;GER") before passing the String to the XML object. There are several possibilities to do this, maybe this link is helpful: http://stackoverflow.com/questions/994331/java-how-to-unescape-html-character-entities-in-java

link

answered 11.01.2017 at 16:43

Barbara%20Brugger's gravatar image

Barbara Brugger ♦♦
(suspended)
accept rate: 100%

edited 11.01.2017 at 16:44

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5

Asked: 10.01.2017 at 12:42

Seen: 1,998 times

Last updated: 11.01.2017 at 16:44