Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Output encoding in Java mapping ?

Hello,

I have written a Java mapping which reads an input document and creates an output document. My problem is, the German special characters are lost in the output document (wrong characters). This is strange, because I am only using regular DOM methods for adding the output nodes and values. Anybody has an idea where I have to explicitly define the output encoding ? XI automatically uses UTF-8, I am using the StandardDOMWriter class of the com.inqmy.lib.xml package from XI, and DocumentBuilder from javax.xml.parsers.

But the output is wrong nevertheless. I think the encoding is already set in the OutputStream input variable of the execute methods. So no need to be changed (?)

Code sample below:

public void execute(InputStream in, OutputStream out) throws StreamTransformationException {

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

Document idoc = documentBuilder.parse(in); // input document

Document odoc = documentBuilder.newDocument(); // output document

// create some elements and values with helper method below

// [..]

// write output document to stream

odoc.appendChild(oRoot);

StandardDOMWriter sdw = new StandardDOMWriter();

sdw.write(odoc, out, null);

}

private Element createElement(String elementName, String value, Element parent, Document doc) {

Element element = createElement(elementName, parent, doc);

// here we put the input content to output value

element.appendChild(doc.createTextNode(value));

// ok, special character still there:

trace.addInfo("Read back: " + getNodeValue(element));

return element;

}

CSY

Not what you were looking for? View more on this topic or Ask a question