on 09-10-2010 1:00 PM
hi,
i get by testing in PI 7.1 (operation mapping) this ERROR:
"Unable to display tree view; Error when parsing an XML document (Content is not allowed in prolog.)"
this is my java-programm-code:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.sap.aii.mapping.api.StreamTransformation;
import java.io.*;
import java.util.Map;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
/*IMPORT statement imports the specified classes and its methods into the program */
/Every Java mapping program must implement the interface StreamTransformation and its methods execute() and setParameter() and extend the class DefaultHandler./
public class Mapping extends DefaultHandler implements StreamTransformation {
/*
Below is the declaration for all the variables we are going to use in the
subsequent methods.
*/
private Map map;
private OutputStream out;
private boolean input1 = false;
private boolean input2 = false;
private int number1;
private int number2;
private int addvalue;
private int mulvalue;
private int subvalue;
String lineEnd = System.getProperty("line.separator");
/*
setParamater() method is used to store the mapping object in the variable
"map"
*/
public void setParameter(Map param) {
map = param;
}
public void execute(InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException {
DefaultHandler handler = this;
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
SAXParser saxParser = factory.newSAXParser();
this.out = out;
saxParser.parse(in, handler);
} catch (Throwable t) {
t.printStackTrace();
}
}
/*
As seen above execute() method has two parameters "in" of type
InputStream and "out" of type OutputStream. First we get a new instance
of SAXParserFactory and from this one we create a new Instance of
SAXParser. To the Parse Method of SaxParser, we pass two parameters,
inputstream "in" and the class variable "handler".
*/
/*
Method "write" is a user defined method, which is used to write the
string "s" to the outpurstream "out".
*/
private void write(String s) throws SAXException {
try {
out.write(s.getBytes());
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
}
}
public void startDocument() throws SAXException {
write("");
write(lineEnd);
write("");
write(lineEnd);
}
public void endDocument() throws SAXException {
write("");
try {
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
}
}
public void startElement(String namespaceURI, String sName, String qName,
Attributes attrs) throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if (eName.equals("NUMBER1"))
input1 = true;
if (eName.equals("NUMBER2"))
input2 = true;
}
public void endElement(String namespaceURI, String sName, String qName)
throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if (eName.equals("NUMBER1"))
input1 = false;
if (eName.equals("NUMBER2"))
input2 = false;
}
public void characters(char[] chars, int startIndex, int endIndex)
throws SAXException {
String dataString = new String(chars, startIndex, endIndex).trim();
if (input1) {
try {
number1 = Integer.parseInt(dataString);
} catch (NumberFormatException nfe) {
}
}
if (input2) {
number2 = Integer.parseInt(dataString);
}
if (input2 == true) {
addvalue = number1 + number2;
mulvalue = number1 * number2;
subvalue = number1 - number2;
write("" + addvalue + "");
write(lineEnd);
write("" + mulvalue + "");
write(lineEnd);
write("" + subvalue + "");
write(lineEnd);
}
}
}
in developer studio 7.1 i dont get error.
this happens by testing the mapping-programm in ESR.
can somebody help me please?
Make sure that the xml created out after the java mapping is a valid xml with only one root node.
Regards,
Prateek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.