0

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"))
user85421
  • 28,957
  • 10
  • 64
  • 87
Fadi
  • 23
  • 5

1 Answers1

0

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".

Michael Kay
  • 156,231
  • 11
  • 92
  • 164