Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to set encoding and version. #273

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe<ObjectReceiver<Str
private static final String BEGIN_CLOSE_ELEMENT = "</";
private static final String END_CLOSE_ELEMENT = ">";

private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
private static final String XML_HEADER = "<?xml version=\"%s\" encoding=\"%s\"?>\n";
private static final String XMLNS_MARKER = " xmlns";

private final StringBuilder builder = new StringBuilder();
Expand All @@ -75,6 +75,9 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe<ObjectReceiver<Str
private Map<String, String> namespaces = new HashMap<String, String>();
private boolean writeRootTag = true;
private boolean writeXmlHeader = true;
private String xmlHeaderEncoding = "UTF-8";
private String xmlHeaderVersion = "1.0";

private boolean separateRoots;

private Element element;
Expand Down Expand Up @@ -116,6 +119,10 @@ public void setWriteXmlHeader(final boolean writeXmlHeader) {
this.writeXmlHeader = writeXmlHeader;
}

public void setXmlHeaderEncoding(final String xmlHeaderEncoding) { this.xmlHeaderEncoding = xmlHeaderEncoding; }

public void setXmlHeaderVersion(final String xmlHeaderVersion) { this.xmlHeaderVersion = xmlHeaderVersion; }

public void setWriteRootTag(final boolean writeRootTag) {
this.writeRootTag = writeRootTag;
}
Expand Down Expand Up @@ -208,7 +215,7 @@ private void sendAndClearData() {

private void writeHeader() {
if (writeXmlHeader) {
builder.append(XML_HEADER);
builder.append(String.format(XML_HEADER, xmlHeaderVersion, xmlHeaderEncoding));
}
if (writeRootTag) {
builder.append(BEGIN_OPEN_ELEMENT);
Expand Down