Fadi
Fadi

Reputation: 23

Escaping double quote is not working properly Jdom2

I am writing a parser in Java where I am writing a string in XML dom. my problem is a String "test" should come as "test" but it is coming as "test"

Here is my code

Element elment1 = new Element("string");
elment1.addContent("test");

i get it in the xml like this

<string>"test"</string>

but i want to get it like this

<string>&quot;anytext&quot;</string>

i use this to creat the xml file

Document doc = new Document(root);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.output(doc,new FileWriter("path"))

Upvotes: 0

Views: 150

Answers (1)

Michael Kay
Michael Kay

Reputation: 163322

If you use a standard off-the-shelf serializer, it will not escape a double-quotation-mark " appearing in a text node as an entity reference; it will only escape things that actually need to be escaped.

I can't imagine why you would want this unnecessary escaping, but it you do, you will need to do the serialization yourself "by hand".

Upvotes: 0

Related Questions