0

After make changes inside XML file I want to save my result. I'm using below code:

OutputStream outputStream = new FileOutputStream(
    new File("C:\\Users\\ABC\\Desktop\\abc.xml")
);
OutputFormat outputFormat = new OutputFormat(doc, "UTF-8", true);
outputFormat.setOmitComments(true);
outputFormat.setLineWidth(0);

XMLSerializer serializer = new XMLSerializer(outputStream, outputFormat);
serializer.serialize(doc);
outputStream.close();  

But into my XML is added line:

<?xml version="1.0" encoding="UTF-8"?>

How to remove it or avoid to add it?

1 Answer 1

0

I found solution. Below line need to be added:

outputFormat.setOmitXMLDeclaration(true);

And works perfect!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.