PI 7.1 + Java SAX
Hi all,
we have recently installed PI 7.1 SPS 6. But now we are having issues with XSL mappings. Every XSL mapping results in this error:
SAXException during XSLT processing, cannot create source for input: Thrown: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:189)
Are we missing a deployment or anything else?
Any ideas?
Tanks in advance!
Regards,
Benjamin
Hi Benjamin,
Confimr whether you have the below jar files imported in your PI server.
jaxp.jar, crimson.jar, and xalan.jar
Thanks
Prabhakar
Similar Messages
-
JAVA Sax mapping replaces &_amp; with & causing mapping to fail
Hi all,
I have the following mapping scenario:
Source XML -> Java Sax Mapping -> Graphical Mapping -> Target structure
The source XML is valid and caters for special characters like & which appear as &_amp; in the XML (ignore the underscore _ without it the editor strips the amp;, isn't that ironic!).
The second step of the interface mapping, which is the graphical map, is failing. It seems that the Java Sax mapping is replacing &_amp; with & in the XML, which is then causing the graphical map to fail as it cannot handle the special character &.
Is there anyway I can prevent the Java Sax mapping from changing & to &
Or is the only solution for me to write extra code in the Java map to convert & back to &_amp; before passing to the second mapping step????
Any help appreciated.
Che
Edited by: Che Eky on Feb 18, 2009 11:05 PMHi..
Use this in your source xml file for '&' ->"&_amp;" remove the underscore
Regards..
Krishna..
Edited by: PrasannaKrishna Mynam on Feb 19, 2009 2:20 PM
Edited by: PrasannaKrishna Mynam on Feb 19, 2009 2:20 PM -
Java SAX parser. How to get raw XML code of the currently parsing event?
Java SAX parser, please need a clue how to get the raw XML code of the currently parsing event... needed for logging, debugging purposes.
Here's and example, letting me clarify exactly what i need: (see the comments in source)
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
//..Here... or maybe somewhere elsewhere I need on my disposal the raw XML code of
//..every XML tags received from the XML stream. I need simply to write it down
//..in a log file, for debugging purposes, while parsing. Can anyone give me a suggestion
//..how can i implement such logging while the SAX parser only returns me the tagname and
//..attributes. While parsing I want to log the XML code for every tag in
//..its 'pure form', like it is comming from the server directly on the
//..socket's input reader.
if ("p".equals(qName)) {
etc...
}Than you in advance.YES!
I've solved my problem using class RecordingInputStream that wraps the InputStream
here is the class source code:
import java.io.ByteArrayOutputStream;
import java.io.FilterInputStream;
import java.io.InputStream;
import java.io.IOException;
* @author Unknown
class RecordingInputStream extends FilterInputStream {
protected ByteArrayOutputStream sink;
RecordingInputStream(InputStream in) {
this(in, new ByteArrayOutputStream());
RecordingInputStream(InputStream in, ByteArrayOutputStream sink) {
super(in);
this.sink = sink;
public synchronized int read() throws IOException {
int i = in.read();
sink.write(i);
return i;
public synchronized int read(byte[] buf, int off, int len) throws IOException {
int l = in.read(buf, off, len);
sink.write(buf, off, l);
return l;
public synchronized int read(byte[] buf) throws IOException {
return read(buf, 0, buf.length);
public synchronized long skip(long len) throws IOException {
long l = 0;
int i = 0;
byte[] buf = new byte[1024];
while (l < len) {
i = read(buf, 0, (int)Math.min((long)buf.length, len - l));
if (i == -1) break;
l += i;
return l;
byte[] getBytes() {
return sink.toByteArray();
void resetSink() {
sink.reset();
} Then here is the initialization before use with SAX:
this.psock = new Socket(this.profile.httpServer, Integer.parseInt(this.profile.httpPort));
this.out = new PrintWriter(this.psock.getOutputStream(), true);
this.ris=new RecordingInputStream(this.psock.getInputStream());
this.in=new BufferedReader(new InputStreamReader(this.ris));
try {
this.parser = SAXParserFactory.newInstance().newSAXParser();
this.parser.parse(new InputSource(this.in),new XMLCommandsHandler());
catch (IOException ioex) { }
catch (Exception ex) { }Then the handler class looks like this (it will be an inner class, so you can access ris, from the parent class):
class XMLCommandsHandler extends DefaultHandler {
public void startDocument() throws SAXException {
//...nothing
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
// BEGIN - Synchronized logging of raw XML source code in parallel with SAX parsing :)
byte[] bs=ris.getBytes();
logger.warn(new String(bs));
ris.resetSink();
// End logging
if ("expectedTagThatTriggersMeToDoSomething".equals(qName)) {
//...Do smth.
}Edited by: patladj on Jul 3, 2008 12:30 PM -
Hello All
I need a xml, sax example.....
If I have a XML document like
Input.xml
<film>
<artistes>
<name>Art1</name>
<name>Art2</name>
<artistes>
<technicians>
<tech> Camera </tech>
<tech> Direction </tech>
<technicians>
</film>
I want the xml to be verified against a DTD (please come up with the DTD for the above xml, sorry). And the output xml should be of the form
<finearts>
<artistes>
<name>Art1</name>
<name>Art2</name>
<artistes>
<technicians>
<tech> Camera </tech>
<tech> Direction </tech>
<technicians>
<finearts>
Basically film node is replaced by finearts.
I can appreciate if I can get a java program which does this.
The java class should have 2 methods, one whch takes input xml as string, and the other which takes as filename. I need this to be using SAX parser.
Repeating
1. Take xmlinput either as a string or as a file.
2. Validate against DTD.
3. Perform the transform.
4. Write the result to a file.
ThanksForte can auto generate a sax parser for you. Just mount the correct directory and right click on the dtd, and select SAX handler wizard.
-
Hi, I'm using SAX mapping, but in case that some field has "&" as content, for example company name,
public void characters(char buf[], int offset, int len)
throws SAXException {
String s = new String(buf, offset, len);
for string "name m&s" returns only "s". It loops(splits this string into 3) trough:
1. "name m"
2. "&"
3. "s"
and in this case, I get only "s" what is completely wrong. How to avoid that?
br
marioHi
Can you convert the character & to "& a m p ;" whithout white spaces?
"& a m p ;" is the correct value for some XML parsers, or try to use other character set.
Regards
Ivá -
JAVA-SAX-Xml how to get simple tag element names to a list
i need to get the simple tag names(here it is name,price,aname,city) in to a list i have heard about SAX parser event driven it walks throgh the xml step by step when a new tag occurs it will parse etc....
but i am unable to get the only sampletag names into a Arraylist
i have heard about a method getElementBytagName()
i dont want to write a code for particular xml because later on i have to retrive same simple tags from another xml say employee.xml
please provide a generic code which will retrive the simple tag names and stores into a Arraylist
the real xml i want to store only simple elements into array list
<ProvisionViewingCardprovisionViewingCar>
<orderId>1</orderId>
<numberOfCards>2</numberOfCards>
<customerSite>
<customerSiteSystemId>3</customerSiteSystemId>
<customerSiteID>4</customerSiteID>
<customerSiteState>5</customerSiteState>
<parentCustomerSiteID>6</parentCustomerSiteID>
<businessName>7</businessName>
<migratedCustomerID>8</migratedCustomerID>
<businessContactInformation>
<contactID>9</contactID>
<emailInfo>
<additionalEmailAddress>10</additionalEmailAddress>
<emailAddress>11</emailAddress>
</emailInfo>
<communicationPreference>12</communicationPreference>
<mobileNumber>13</mobileNumber>
<faxNumber>14</faxNumber>
<contactExceptions>15</contactExceptions>
<telephoneNumber>16</telephoneNumber>
</businessContactInformation>
<address>
<addressID>17</addressID>
<addressLine1>18</addressLine1>
<addressLine2>19</addressLine2>
<addressLine3>20</addressLine3>
<town>21</town>
<county>22</county>
<postCode>22_1</postCode>
<country>23</country>
</address>
<person>
<personID>24</personID>
<title>25</title>
<firstName>26</firstName>
<middleName>27</middleName>
<dataProtectionPreference>28</dataProtectionPreference>
<surname>29</surname>
<dateOfBirth>30</dateOfBirth>
<position>31</position>
<!--1 or more repetitions:-->
<authority>32</authority>
<address>
<addressID>33</addressID>
<addressLine1>34</addressLine1>
<addressLine2>35</addressLine2>
<addressLine3>36</addressLine3>
<town>37</town>
<county>38</county>
<postCode>39</postCode>
<country>40</country>
</address>
Regards/
Suman.i need to get the simple tag names(here it is name,price,aname,city) in to a list i have heard about SAX parser event driven it walks throgh the xml step by step when a new tag occurs it will parse etc....
but i am unable to get the only sampletag names into a Arraylist
i have heard about a method getElementBytagName()
i dont want to write a code for particular xml because later on i have to retrive same simple tags from another xml say employee.xml
please provide a generic code which will retrive the simple tag names and stores into a Arraylist
the real xml i want to store only simple elements into array list
<ProvisionViewingCardprovisionViewingCar>
<orderId>1</orderId>
<numberOfCards>2</numberOfCards>
<customerSite>
<customerSiteSystemId>3</customerSiteSystemId>
<customerSiteID>4</customerSiteID>
<customerSiteState>5</customerSiteState>
<parentCustomerSiteID>6</parentCustomerSiteID>
<businessName>7</businessName>
<migratedCustomerID>8</migratedCustomerID>
<businessContactInformation>
<contactID>9</contactID>
<emailInfo>
<additionalEmailAddress>10</additionalEmailAddress>
<emailAddress>11</emailAddress>
</emailInfo>
<communicationPreference>12</communicationPreference>
<mobileNumber>13</mobileNumber>
<faxNumber>14</faxNumber>
<contactExceptions>15</contactExceptions>
<telephoneNumber>16</telephoneNumber>
</businessContactInformation>
<address>
<addressID>17</addressID>
<addressLine1>18</addressLine1>
<addressLine2>19</addressLine2>
<addressLine3>20</addressLine3>
<town>21</town>
<county>22</county>
<postCode>22_1</postCode>
<country>23</country>
</address>
<person>
<personID>24</personID>
<title>25</title>
<firstName>26</firstName>
<middleName>27</middleName>
<dataProtectionPreference>28</dataProtectionPreference>
<surname>29</surname>
<dateOfBirth>30</dateOfBirth>
<position>31</position>
<!--1 or more repetitions:-->
<authority>32</authority>
<address>
<addressID>33</addressID>
<addressLine1>34</addressLine1>
<addressLine2>35</addressLine2>
<addressLine3>36</addressLine3>
<town>37</town>
<county>38</county>
<postCode>39</postCode>
<country>40</country>
</address>
Regards/
Suman. -
Hi All,
Any help is appreciated. Is it possible to start parsing an XML document somewhere in the middle of the document using SAX parser? It will still parse the doc sequentially but has to start at a specified location or sorts instead of starting from the beginning.
Thanks in advance.Sure. Open an InputStream on the document (a FileInputStream or whatever is convenient). Read the part of the InputStream before the document and ignore the data. When you have the InputStream's cursor pointing at the beginning of the document, pass it to the parser.
-
How to create new XML file using retreived XML content by using SAX API?
hi all,
* How to create new XML file using retreived XML content by using SAX ?
* I have tried my level best, but output is coming invalid format, my code is follows,
XMLFileParser.java class :-
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;
public class PdfParser extends XMLFilterImpl {
private TransformerHandler handler;
Document meta_data;
private StringWriter meta_data_text = new StringWriter();
public void startDocument() throws SAXException {
void startValidation() throws SAXException {
StreamResult streamResult = new StreamResult(meta_data_text);
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try
handler = factory.newTransformerHandler();
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
handler.setResult(streamResult);
handler.startDocument();
catch (TransformerConfigurationException tce)
System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
super.startDocument();
public void startElement(String namespaceURI, String localName,
String qualifiedName, Attributes atts) throws SAXException {
handler.startElement(namespaceURI, localName, qualifiedName, atts);
super.startElement(namespaceURI, localName, qualifiedName, atts);
public void characters(char[] text, int start, int length)
throws SAXException {
handler.characters(text, start, length);
super.characters(text, start, length);
public void endElement(String namespaceURI, String localName,
String qualifiedName) throws SAXException {
super.endElement("", localName, qualifiedName);
handler.endElement("", localName, qualifiedName);
public void endDocument() throws SAXException {
void endValidation() throws SAXException {
handler.endDocument();
try {
TransformerFactory transfactory = TransformerFactory.newInstance();
Transformer trans = transfactory.newTransformer();
SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
DOMResult dom_result = new DOMResult();
trans.transform(sax_source, dom_result);
meta_data = (Document) dom_result.getNode();
System.out.println(meta_data_text);
catch (TransformerConfigurationException tce) {
System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
catch (TransformerException te) {
System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
} CreateXMLFile.java class :-
Sax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
* In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
is not an XML type text, it just an Normal text Why that ?
* Please help me what is the problem in my code?
Cheers,
JavaImranSax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
</code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
<code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
* I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
* I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
Thanks,
JavaImran{code} -
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,
SebastianHi Ravi, hi Raman,
thanks so far... I did some changes in my code, but I am still having the same problem... down there you will find my new code and the source message.
there is my new code:
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_mappingOUT xmlns:ns0=\"urn:agrp:xi:geissseb\"><TABLE>");
public void endDocument () throws SAXException {
write("</TABLE></ns0:mt_mappingOUT>");
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("mtset"))
write("<item>");
if(eName.substring(0,2).equals("se"))
write("<Item_FIELD_"eName.substring(13,14)">");
public void endElement (String namespaceURI, String sName, String qName) throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("mtset"))
write("</item>");
if(eName.substring(0,2).equals("se"))
write("</item_FIELD_"eName.substring(13,14)">");
public void characters (char buf[], int offset, int len)
throws SAXException {
String s = new String(buf, offset, len);
write (s);
and there is the source message:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:agrp:xi:geissseb" targetNamespace="urn:agrp:xi:geissseb">
<xsd:element name="mt_MappingOut" type="dt_MappingOut" />
<xsd:complexType name="dt_MappingOut">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
4c79fbb0bde711dcae43001a4b0af224
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="set">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366510aeda11dcb3bb00174205b856
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="set_ELEMENT_01" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366511aeda11dcaf2600174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_02" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366512aeda11dc84d400174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_03" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366513aeda11dcbcab00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_04" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366514aeda11dc96a300174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_05" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366515aeda11dca77700174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_06" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366516aeda11dc8f7d00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_07" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366517aeda11dcc24b00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_08" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366518aeda11dc92cd00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_09" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366519aeda11dcc9b100174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_10" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b36651aaeda11dcc5a700174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I really hope you can help me there..
Thanks in advance..
Sebastian -
Hi All,
After faceing so much of problem, i found that it would be better if i can go for an XSLT/java mapping:
1. It is adding an extra <b>ns0</b> to header line & end line which i dont want to be generated in the output xml file.
2. Namespace problem that basically sticking to 60 but i want 72 characters in my target xml file.
3. No carriage return at the end of each line which is not geting generated through graphical mapping.
Now i have an XSD provided by the client. So how can i use that and which mapping should best suits to solve all these problem.
Should i go for a java mapping or an XSLT/JAVA mapping.
I dont have any idea on both of them, So can you people send me the details for it.
Many Thanks & Best Regards,
JGD.Hi,
Based on the requirement and size we can choose the mapping.
If java is suitable to our requirement then we go for java.
If XSLT is suitable to our requirement then we go for XSLT.
Performance wise(high --> low) :
If data is less then
Graphical mapping -
> Java(sax parser)mapping -
> Java(dom parser)mapping -
> XSLT mapping -
> ABAP mapping.
If data is high then
XSLT mapping -
> Java(sax parser)mapping -
> Graphical mapping(internally it uses SAX)----> Java(dom parser)mapping -
> ABAP mapping.
If you choose XSLT then you can select Altova Map Force tool then no need to write the XSLT code here, it will automatically generates the code.
N:1 XSLT Mapping
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/30ac53f2-21d7-2a10-afa2-ce1a0577ca18
XSLT mapping https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/006aa890-0201-0010-1eb1-afc5cbae3f15 -
Container Object in Java Class
Hello ,
I have a Mapping program using java class type (Java SAX in this case). I need to access some Runtime constants and the mapping trace object.
In message mapping is simple. We can use the container object that is pass to a UDF and the GlobalContainer Object.
But how can I access the Runtime constants and mapping trace without a container object ?.
Any ideas...?
Thanks in advance.
Yuvan D.in Your java mapping class
you should import import com.sap.aii.mapping.api.*;
public void execute(InputStream input, OutputStream output)
throws StreamTransformationException {
AbstractTrace trace = null;
String RESULT = new String();
trace =
(AbstractTrace) param.get(
StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo(doc.toString());
http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm -
Problems with Java DOM Mapping
Hi Experts,
as part of my diploma-thesis I have to write a java DOM-Mapping, which mapps the following incoming message:
<mt_MappingOUT>
<set>
<set_Element_01>...</set_Element_01>
<set_Element_02>... </set_Element_02>
<set_Element_03>... </set_Element_02>
<set_Element_10> </set_Element_10>
</set>
</mt_MappingOUT>
to the following outgoinig message:
<mt_MappingIN>
<TABLE>
<item>
<item_FIELD_01> </item_FIELD_01>
<item_FIELD_10> <item_FIELD_10>
<i/tem>
</TABLE>
</mt_MappingIN>
I am not a very experienced Java-Developer. You can see my code down there, which I tried to implement according to some bloggs; unfortunately the result is not what I want to have
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class DOMMAPPING implements StreamTransformation{
public static void main(String[] args) throws Exception
try
FileInputStream fin =
new FileInputStream("C:/mt_MappingOut.xml");
FileOutputStream fout =
new FileOutputStream("C:/target.xml");
DOMMAPPING mapping = new DOMMAPPING();
mapping.execute(fin, fout);
catch (Exception e) {
e.printStackTrace();
public void setParameter (Map param) {}
public void execute (InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document documentIn = null;
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
try {
Element itemNode = null;
NodeList[] list_f=new NodeList[10];
Element[] field=new Element[10];
documentIn = builder.parse(in);
Document documentOut = builder.newDocument();
Element rootNode = documentOut.createElementNS("urn:agrp:xi:geissseb","ns0:mt_MappingIn");
documentOut.appendChild(rootNode);
Element tableNode = documentOut.createElement("TABLE");
rootNode.appendChild(tableNode);
NodeList list_Set=documentIn.getElementsByTagName("set");
System.out.println(list_Set.getLength());
for(int j=1;j<10;j++){
list_f[j-1]=documentIn.getElementsByTagName("set_ELEMENT_01"+j);
list_f[9]=documentIn.getElementsByTagName("set_ELEMENT_10");
//NodeList list_f01=documentIn.getElementsByTagName("f01");
for (int i=0;i<list_Set.getLength();i++)
itemNode=documentOut.createElement("item");
tableNode.appendChild(itemNode);
for(int k=0; k<10;k++){
Node f=list_f[k].item(i);
f=f.getFirstChild();
String str_f=f.getNodeValue();
Text text_f=documentOut.createTextNode(str_f);
field[k]=documentOut.createElement("item_FIELD_"(k1));
field[k].appendChild(text_f);
itemNode.appendChild(field[k]);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();
transform.transform(new DOMSource(documentOut), new StreamResult(out));
} catch (SAXException e2) {
e2.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}catch (Throwable t) { throw new StreamTransformationException("error", t); }
Unfortunately there seems to be at least one error in there because the result I get is just the following:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <ns0:mt_MappingIn xmlns:ns0="urn:agrp:xi:geissseb">
<TABLE />
</ns0:mt_MappingIn>
Below you will find my source message:
<?xml version="1.0" encoding="UTF-8" ?>
- <xsd:schema targetNamespace="urn:agrp:xi:geissseb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:agrp:xi:geissseb">
<xsd:element name="mt_MappingOut" type="dt_MappingOut" />
- <xsd:complexType name="dt_MappingOut">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">a7a28830bebf11dc81aa001a4b0af224</xsd:appinfo>
</xsd:annotation>
- <xsd:sequence>
- <xsd:element name="Set">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366510aeda11dcb3bb00174205b856</xsd:appinfo>
</xsd:annotation>
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="f01" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366511aeda11dcaf2600174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_02" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366512aeda11dc84d400174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_03" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366513aeda11dcbcab00174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_04" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366514aeda11dc96a300174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_05" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366515aeda11dca77700174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_06" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366516aeda11dc8f7d00174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_07" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366517aeda11dcc24b00174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_08" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366518aeda11dc92cd00174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_09" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b366519aeda11dcc9b100174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
- <xsd:element name="set_ELEMENT_10" type="xsd:string">
- <xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">0b36651aaeda11dcc5a700174205b856</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
When I had problems withe Java SAX Mapping, I got great hints in the forum. So I hope you can help me out again...
Cheers SebastianHere you go.
Code
package com.sap.test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.crimson.tree.TextNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
import com.sap.aii.mapping.api.StreamTransformationException;
public class DomTest {
Document documentOut = null;
public static void main(String[] args) throws Exception
try
FileInputStream fin = new FileInputStream("test.xml");
FileOutputStream fout = new FileOutputStream("test_out.xml");
DomTest mapping = new DomTest();
mapping.execute(fin, fout);
catch (Exception e) {
e.printStackTrace();
public void setParameter (Map param) {}
public void execute (InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document documentIn = null;
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
try {
Element itemNode = null;
//NodeList[] list_f=new NodeList10;
//Element[] field=new Element10;
documentIn = builder.parse(in);
documentOut = builder.newDocument();
Element rootNode = documentOut.createElementNS("urn:agrp:xi:geissseb","ns0:mt_MappingIn");
rootNode.setAttribute("xmlns:ns0", "urn:agrp:xi:geissseb");
documentOut.appendChild(rootNode);
Element tableNode = documentOut.createElement("TABLE");
rootNode.appendChild(tableNode);
NodeList list_Set = documentIn.getElementsByTagName("set");
System.out.println(list_Set.getLength());
for(int j = 0 ; j < list_Set.getLength() ;j++){
Element setNode = (Element)list_Set.item(j);
NodeList children = setNode.getChildNodes();
for(int index = 0; index < children.getLength(); index++)
Node child = children.item(index);
if (child instanceof Element) {
Element element = (Element) child;
if(element.getNodeName().startsWith("set_ELEMENT"))
createItemFeildNode(tableNode,element);
//list_f[9]=documentIn.getElementsByTagName("set_ELEMENT_10");
// NodeList list_f01=documentIn.getElementsByTagName("f01");
/*for (int i=0;i<list_Set.getLength();i++)
itemNode=documentOut.createElement("item");
tableNode.appendChild(itemNode);
for(int k=0; k<10;k++){
Node f=list_f[k].item(i);
f=f.getFirstChild();
String str_f=f.getNodeValue();
Text text_f=documentOut.createTextNode(str_f);
field[k]=documentOut.createElement("item_FIELD_"(k1));
field[k].appendChild(text_f);
itemNode.appendChild(field[k]);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();
transform.transform(new DOMSource(documentOut), new StreamResult(out));
transform.transform(new DOMSource(documentOut), new StreamResult(System.out));
} catch (SAXException e2) {
e2.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}catch (Throwable t) { throw new StreamTransformationException("error", t); }
private void createItemFeildNode(Element root, Element element) {
String inName = element.getNodeName();
int temp = inName.lastIndexOf('_');
if (temp == -1)
return;
String index = inName.substring(temp+1);
String nodeName = "Item_FIELD_" + index;
String nodeVal = element.getFirstChild().getNodeValue();
Element newElement = documentOut.createElement(nodeName);
Text txtNode = documentOut.createTextNode(nodeVal);
newElement.appendChild(txtNode);
root.appendChild(newElement);
Input
<?xml version="1.0" encoding="UTF-8" ?>
<mt_MappingOut xmlns="urn:agrp:xi:geissseb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:agrp:xi:geissseb file:/D:/Eclipse/workspace/SDN/test.xsd">
<set xmlns="">
<set_ELEMENT_01>E1</set_ELEMENT_01>
<set_ELEMENT_02>E2</set_ELEMENT_02>
<set_ELEMENT_03>E3</set_ELEMENT_03>
<set_ELEMENT_04>E4</set_ELEMENT_04>
<set_ELEMENT_05>E5</set_ELEMENT_05>
<set_ELEMENT_06>E6</set_ELEMENT_06>
<set_ELEMENT_07>E7</set_ELEMENT_07>
<set_ELEMENT_08>E8</set_ELEMENT_08>
<set_ELEMENT_09>E9</set_ELEMENT_09>
<set_ELEMENT_10>E10</set_ELEMENT_10>
</set>
</mt_MappingOut>
Output
<?xml version="1.0" encoding="UTF-8" ?>
<ns0:mt_MappingIn xmlns:ns0="urn:agrp:xi:geissseb">
<TABLE>
<Item_FIELD_01>E1</Item_FIELD_01>
<Item_FIELD_02>E2</Item_FIELD_02>
<Item_FIELD_03>E3</Item_FIELD_03>
<Item_FIELD_04>E4</Item_FIELD_04>
<Item_FIELD_05>E5</Item_FIELD_05>
<Item_FIELD_06>E6</Item_FIELD_06>
<Item_FIELD_07>E7</Item_FIELD_07>
<Item_FIELD_08>E8</Item_FIELD_08>
<Item_FIELD_09>E9</Item_FIELD_09>
<Item_FIELD_10>E10</Item_FIELD_10>
</TABLE>
</ns0:mt_MappingIn> -
Fatal error in Java Parser V2 :Status??
We still have a problem with entity references
in V2 of the JAVA XML parser (see Rolf van Deuresen 24-11).
It is a very urgent problem for us. We think that the XML-team
is working on it. Can you inform me abouth the status with the
(bug??)-fix. If you need more information on the problem, please
ask.
Greetings,
Erik van den Berg.
nullAttachments: "1|type=text/plain|desc=SAXSample output|17142|file=output.txt|"
Oracle XML Team wrote:
: Erik van den Berg (guest) wrote:
: : Oracle XML Team wrote:
: : : Erik van den Berg (guest) wrote:
: : : : We still have a problem with entity references
: : : : in V2 of the JAVA XML parser (see Rolf van Deuresen 24-
11).
: : : : It is a very urgent problem for us. We think that the
XML-
: : team
: : : : is working on it. Can you inform me abouth the status
with
: : the
: : : : (bug??)-fix. If you need more information on the
problem,
: : : please
: : : : ask.
: : : : Greetings,
: : : : Erik van den Berg.
: : : Have you downloaded the latest version 2.0.2.5 that was
made
: : : available this week?
: : : Oracle XML Team
: : : http://technet.oracle.com
: : : Oracle Technology Network
: : I have downloaded the new version 2.0.2.5 of the Java
parser,
: : and it stil doesn't work. Please refer to the original
message
: : from Rolf van Deursen (24th november 1999) for the details.
: : Maybe it will help you if I mail you a XML file that fails.
If
: : so, please give me your email account.
: : Greetings,
: : Erik van den Berg.
: You can attach files to messages in the forum here.
: Oracle XML Team
: http://technet.oracle.com
: Oracle Technology Network
Here's the XML that raises the Fatal error. The following
information is generated by the parser:
Fatal Error of Java SAX parser v2.0.2.5:
XML-0121: (Fatal Error) End tag does not match start
tag 'WOONPLAATS'. at line 517, column 4151 of XML document.
I attached the output of the SAXSample class, so you can trace
the line and column where the error occurs. Also attached is the
XML file (4Mb).
An other error that occurs with this XML is the following
situation:
<VOLGNR_FILM> 001</VOLGNR_FILM>
this piece of XML is parsed with the following events:
StartElement:VOLGNR_FILM
Characters:NR_
Characters:001
EndElement:VOLGNR_FILM
So the spaces are replace with a part of the start tag! This is
also only with large files. I tested this piece of XML in a
seperate file. Then it was parsed correctly.
Kind regards,
Erik.
null -
Fatal error XML-0121 in a valid XML file in v2 of SAX parser
Attachments: "1|type=text/plain|desc=Logging of Fatal error using v2 of SAX parser |file=v2_loggin
.txt|";"2|type=text/plain|desc=Logging of Fatal error using v2 of java SAX parser |17078|file=v2_l
gging.txt|"
Dear XML team,
I am using the SAX parser version 2.0.2.4. When parsing a valid
XML of approx. 3,5 Megabytes i get a fatal error XML-0121
saying 'End tag does not match start tag
<CORRESPONDENTIENAAM1>...'
We checked the xml on the well formedness with tools like XML
Spy and IE5. The XML is valid!
We did some testing on the XML with the SAXSample class and we
noticed that the error is related to the use of Entity
References. When we removed the Entity Reference ' the XML
was parsed correctly.
We also noticed that if we cut the XML in two smaller parts it
was also parsed correctly.
I attached the output of the parser, as well as the output of
the SAXSample class.
I hope you can fix this problem!
With kind regards,
Rolf van Deursen.
nullUpdate: I have attempted to use xmlparserv2.jar dated 12/23/08 that is packaged with jDeveloper 11g preview, but am still receiving the same message.
-
For what its worth, the Java SAX XML had/has a killer gotcha that one must compensate for or it does not work.
Essentially, a SAX parser has five routines one has to program:
startDocument
startElement
characters
endElement
endDocument
The characters routine is where the contents of a tag appear.
Suppose the underlying disk read routine does a read of the
input stream that does not terminate at a tag; that has to happen
occasionally. Then all the characters routine will see is part
of a tag's contents. The next read of the input stream will
cause characters to be called again with the second half of
the tag's contents in the buffer. The application has to be
smart enough to append the second half of the tag's contents
to the first half, or there will be an error. My solution was
to initialize a string in startElement, always append to it in
characters, and call it the contents of the tag in endElement.
This seems to work for me.
It took weeks to find and fix this error. And as far as I know
there is no defense against it, other than the one I outined above.
I have read several books on XML and have never seen this problem
described.
Has anyone else ever seen this problem and have a better soln
for it?
Charles ElliottFrom the API documentation for the characters() method of org.xml.sax.ContentHandler:
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.You ask if anyone else has ever seen the problem? Actually it's an FAQ in this forum. Appears every couple of weeks. You've found the correct way to handle it. (Although using a StringBuilder instead of a String to accumulate the data might be a tiny bit better.)
Maybe you are looking for
-
Sender file adapter - filename containing * does not work
Hi All, I am doing simple file-file scenario wherein my filename is something like MATMAS05_XI20070911-150159-088.xml there are many files having similar kind of name which are supposed to be picked so simply I can go on writing <b>MATMAS05_XI*.xml
-
Does a person need Adobe Reader in order to use a fillable PDF form?
I have created a fillable form using Acrobat XI and I find that some persons are unable to use it while others are. Does a person need Adobe Reader to use the fillable form? If so, how easy is it to download? Thank you
-
Dear All, I have created a web service from a function module. I have also created a proxy for the web service. Before creating the logical port, I am also including the same port name in the endpoint of the service. My scenario is, I am creating and
-
I have a workaround - but it seems an overkill
I finally have got something to work.. but surely this can't be the way - can someone from the BC4J/uiXML group confirm that this is the only way --- My update page definition has changed - I added the usesCurrency clause - <bc4j:registryDef> <bc4j:r
-
Hyperion Planning and Varying attribute
Hi Can some help me in having varying attribute in Hyperion Planning application. Does Hyperion planning support Varying attribute concept? Regards Shyamkant