Skip to Content
0
Former Member
Jan 07, 2008 at 03:53 PM

Problems with a Java Mapping

33 Views

Hi Experts,

as part of my diploma-thesis I have to write a java SAX-Mapping, which mapps the following incoming message:

mt_MappingOUT

set

set_Element_01

set_Element_02

set_Element_03

.

.

set_Element_10

to the following outgoinig message:

mt_MappingIN

TABLE

item

item_FIELD_01

.

.

.

item_FIELD_10

I develped the following code, which unfortunately results in "XML is not well defined" while testing. Unfortunately I cannot find the problem. So I hope someone of you can have a look an will have an idea.

/*

  • Created on 20.12.2007

*/

/**

  • @author Sebastian Geissler

*/

import java.io.FileInputStream;

import java.io.FileOutputStream;

import com.sap.aii.mapping.api.*;

import java.io.*;

import java.util.Map; import javax.xml.parsers.*;

import org.xml.sax.; import org.xml.sax.helpers.;

public class SETtoITEMjavaSAX extends DefaultHandler implements StreamTransformation

{

private Map map;

private OutputStream out;

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();

}

}

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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

write("<ns0:mt_MappingIn xmlns:ns0=\"urn:agrp:xi:geissseb\"><TABLE>");

}

public void endDocument () throws SAXException

{

write("</TABLE></ns0:mt_MappingIn>");

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("set"))

write("<item>");

if(eName.substring(0,6).equals("set_E"))

write("<item_FIELD"eName.substring(10,13)">");

}

public void endElement (String namespaceURI, String sName, String qName) throws SAXException

{

String eName = sName;

if ("".equals(eName))

eName = qName;

if(eName.equals("set"))

write("</item>");

if(eName.substring(0,6).equals("set_E"))

write("</item_FIELD"eName.substring(10,13)">");

}

public void characters (char buf[], int offset, int len)

throws SAXException {

String s = new String(buf, offset, len);

write (s);

}

}

Thank you,

Sebastian