In Java Mapping Whether to SAX or DOM ?

While implementing Java Mapping which of the following SAX , DOM parsers  is the most efficient way to implement it.
I mean considering the voulume of data in the XML format is large which  usage will give me most  optimal performance .
It would be nice if someone could give a sample most  optimal java code using JAXP where  input stream is read  and after  processing written to  output stream.
regards
Nilesh Taunk.

Hi Nilesh,
>>>While implementing Java Mapping which of the following SAX , DOM parsers is the most efficient way to implement it.
there's no one good answer fot this question
except: it depends:)
SAX and DOM are a little different parsers
so it depends what will your java mapping
have to do: if it will change the
structure or maybe it will only change a few tags,
or maybe it will do something else
have a look at the page below to read a simple
comparision between SAX and DOM
http://www.scit.wlv.ac.uk/~jphb/cp2101/week4/XML_Parsing.html
or this thread:
http://www.biglist.com/lists/xsl-list/archives/200301/msg01318.html
they will give you some idea which one to choose
depending on your requirements
BTW
remember use java mappings only
if you cannot use graphical mapping (very easy debugging)
and if your document cannot be parsed (maybe huge documents)
with XSLT which is supported by many graphilal tools
Regards,
michal
<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>

Similar Messages

  • Java skills for XI java mapping

    I don't want to be novice in Java, wanted to know what is the minimum Java knowledge needed for doing medium complex java mapping. I have done C++ programming during grad school, comfortable with ABAP programming. Please point to books to gain "XI java mapping for dummies". I've started with sun tutorial, but it covers all topics which is difficult to achieve in a short period as my intention was to cover as much XI with java skill to do java mapping.  Also I hear SAX and DOM parsers for mapping between source and target in the forum but don't have sufficient background. Thanks in advance

    Hi,
    You can go thro the java mapping code in these blogs:
    Java mapping blog series:
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
    /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
    /people/rahul.nawale2/blog/2006/07/18/java-mapping-an-alternate-way-of-reading-a-csv-file
    /people/venkataramanan.parameswaran/blog/2006/12/12/java-mapping-to-handle-flat-files-in-sap-xi
    Regarding SAX and DOM there are lot of threads discussing the same issue.
    In Java Mapping Whether to SAX or DOM ?
    Regards,
    P.Venkat

  • Tips on how to write efficient  java code for java mapping

    hi
    I do not have much knowledge in Java
    Can anybody tell me some tips on how to write efficient and optimised java code to be used in java mapping
    Thanks,
    Loveena

    hi D'za,
    JAVA in xi
    A very important place where you will use JAVA in XI is while doing your Mapping. There will be cases when JAVA MAPPING is the best solution to go for. There are 2 types of Parsers available for JAVA Mapping. DOM Parser and SAX parser. Just got through the following links to understand more on Java Mapping and the APIs available.http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/package-summary.html http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Document.html http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
    JAVA mapping -
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii /people/ravikumar.allampallam/blog/2005/06/24/convert-any-flat-file-to-any-idoc-java-mapping /people/amol.joshi2/blog/2006/03/10/think-objects-when-creating-java-mappings /people/sameer.shadab/blog/2005/09/29/testing-abap-mapping
    sample code for java mapping
    Re: Example code DOM PARSER API -
    http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html DOM --- /people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs tutorial sax and dom
    For a tutorial on the methods of SAX and DOM http://java.sun.com/webservices/docs/1.1/tutorial/doc/
    SAX AND dom PARSER ( BY thorsten) -
    example /people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs java mapping example ( testing and debugging) /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
    regards
    biplab
    Use a Good Subject Line, One Question Per Posting - Award Points

  • JAVA mapping using SAX parser adds extra tags

    Hi,
      We are using  java mapping using a SAX parser.It works well in standalone application ie it parses correctly and gets our desired xml structure and the xml is well formed too but when we import it in XI as a jar file it does not throw any errors but adds extra start tags, as a result the output xml is not well formed.XI is adding extra start tags.
    If any one else has faced a similar situation please help.
    Regards,
    Anirban.

    Hi Roberto,
    Thank you for the response.
    As I said, it doesnt throw any error. It is working perfectly in standalone application. But when we deploy it to XI Server, it is not forming the well formed XML. We too are puzzled by this situation.
    Okay, i will explain my scenario here.
    The following is my input XML to the java pgm..
    <Header>
    </Header>
    <Body>
    </Body>
    <SubBody1>
    </SubBody1>
    <SubBody2>
    </SubBody2>
    <SubBody3>
    </SubBody3>
    <SubBody4>
    </SubBody4>
    <Trail>
    </Trail>
    The desired output is
    <Header>
      <Body>
         <NameChanged1>
            <NameChanged2>
    <SubBody3>
    <SubBody4>
    </SubBody4>
    </SubBody3>
    </NameChanged2>
    </NameChanged1>
    <Trail>
    </Trail>
    Just look at the SubBody2 and SubBody1 node, its tag name has been changed in the output XML. Thats y i have decided to use java mapping instead of message mapping.
    I have developed the code for everything, i.e for changing the tag name and for forming the nested xml and it is working fine as a standalone application. But while deploying it to XI, the output is not well formed. I dont know the reason for it. Even I have checked the cardinality of the output Data types, that I have created. Its perfectly okay with all.
    Any Ideas???
    Regards,
    Anirban

  • Java Mapping Using DOM Parser.

    Hi Experts,
    I am new to Java mapping and i have followed the link
    http://scn.sap.com/thread/3173071 and it is working fine. It is for only one item. I have tried to modify the code and i placed a for loop to go create the Output Node based on the No of Input Nodes and it is giving the error as below. But my requirement is
    Input.xml : -
    <?xml version="1.0" encoding="UTF-8" ?>  
    <ns0:DT_Source xmlns:ns0="urn:java_mapping2"> 
    <Person1> 
          <Name>Alex</Name>  
          <Surname>Stewart</Surname>  
    </Person1>
    <Person1> 
          <Name>Sam</Name>  
          <Surname>Abdreson</Surname>  
    </Person1>  
    </ns0:DT_Source>
    Output.xml:-
    <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <ns0:DT_Target xmlns:ns0="urn:java_mapping2"> 
    <Person2> 
         <EmpName> 
              <Emp>Alex Stewart</Emp> 
    </EmpName> 
    </Person2>
    <Person2> 
         <EmpName> 
              <Emp>Sam Abdreson</Emp> 
    </EmpName> 
    </Person2>  
    </ns0:DT_Target> 
    I am unable to get the output. I am getting the following error.
    org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore()
    at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild()
    Please suggest me how i can resolvoe this error.
    Regards,
    GIRIDHAR

    Complete code
    package test;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    import java.io.IOException;
    import org.xml.sax.SAXException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    public class RemoveTag extends AbstractTransformation {
        public void execute(InputStream in,OutputStream out) throws StreamTransformationException, SAXException, IOException {  
            try
                 DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
                 DocumentBuilder builderel=factory.newDocumentBuilder();
                 /*input document in form of XML*/
                 Document docIn=builderel.parse(in);
                 /*document after parsing*/
                 Document docOut=builderel.newDocument();
                 TransformerFactory tf=TransformerFactory.newInstance();
                 Transformer transform=tf.newTransformer();
                 Element root,child,child1,child2;
                 Node textChild;
                 Node name,surname;
                 String fullname="";
                 root=docOut.createElement("ns0:DT_Target");
                 root.setAttribute("xmlns:ns0","urn:java_mapping2");
                 NodeList nList = docIn.getElementsByTagName("Person1");
                 for (int temp = 0; temp < nList.getLength(); temp++)
                child1=docOut.createElement("Person2");
                 child=docOut.createElement("EmpName");
                 child2=docOut.createElement("Emp");
                 child.appendChild(child2);
                 child1.appendChild(child);
                 root.appendChild(child1);
                 name=docIn.getElementsByTagName("Name").item(temp);
                 surname=docIn.getElementsByTagName("Surname").item(temp);
                 fullname=name.getFirstChild().getNodeValue()+" ";
                 fullname+=surname.getFirstChild().getNodeValue();
                 textChild=docOut.createTextNode(fullname);
                 child2.appendChild(textChild);
                 docOut.appendChild(root);  
                 transform.transform(new DOMSource(docOut), new StreamResult(out));
            catch(Exception e)
                 e.printStackTrace();
        public static void main(String[] args) {
            try{
                RemoveTag genFormat=new RemoveTag();
                 FileInputStream in=new FileInputStream("C:\\Users\\Desktop\\aa.xml");
                 FileOutputStream out=new FileOutputStream("C:\\Users\\Desktop\\output1.xml");
                 genFormat.execute(in,out);
            catch(Exception e)
                 e.printStackTrace();
    @Override
    public void transform(TransformationInput arg0, TransformationOutput arg1)
    throws StreamTransformationException {
    // TODO Auto-generated method stub
    try {
        this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

  • Namespace missing in java mapping DOM ?

    Hi,
    I am creating java mapping using DOM, but why i cannot create a namespace using this code ?
    Document targetDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Node docRoot = targetDoc.appendChild(targetDoc.createElementNS("urn:sap-com:atp:ABC40:base", "ns1:Vendor_SQL"));
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    // create source and result wrappers and perform transformation
    DOMSource source = new DOMSource(targetDoc);
    StreamResult result = new StreamResult(outputStream);  
    transformer.transform(source, result);
    expected result in xml :
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Vendor_SQL xmlns:ns0="urn:sap-com:atp:ABC40:base">
    </ns0:Vendor_SQL>
    result :
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Vendor_SQL>
    </ns0:Vendor_SQL>
    Please advise whether i was missing any other required step ?
    Note : testing using NWDS 7.0 SP 17
    Thank You and Best Regards
    Fernand

    Hi Lesmana,
    Can you change the second line in the code like below and give a try::
    Node docRoot = targetDoc.appendChild(targetDoc.createElementNS("ns1:urn:sap-com:atp:ABC40:base", "ns1:Vendor_SQL"));
    Regards,
    ---Saish

  • Java Mapping using DOM

    Hi All,
    I need Java mapping help. I will get incomming payload as following
    <orders>
    <matnr>123</matnr>
    <qty>10</qty>
    </orders>
    i need to change the above payload as follows
    <ns0:orders>
    <ns0:matnr>123</ns0:matnr>
    <ns0:qty>10</ns0:qty>
    </ns0:orders>
    Please help me how to achieve this using Java mapping.
    Regards
    Vijay

    Hi,
    Dom will be quite expensive for this type of requirement since you will have to go to each element and then append the namespace.
    I suggest you use SAX parser which is more  efficient for such requirement.
    The code is given below you can modify it according to your requirement.
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    public class SAXDemo extends DefaultHandler{
         public StringBuffer sb = new StringBuffer();
         public String PREFIX = "ns0:";
         int count = 1;
         public static void main(String[] args)
              SAXDemo demo= new SAXDemo();
              demo.saxdemo();
              System.out.println();
         public void saxdemo()
              InputStream in;
              try
                   in = new FileInputStream(new File("Input.xml"));
                   SAXParserFactory factory = SAXParserFactory.newInstance();
                   factory.setNamespaceAware(true);
                   factory.setValidating(false);
                   SAXParser saxParser = factory.newSAXParser();
                   * Parse the content of the given {@link java.io.InputStream}
                   * instance as XML using the specified
                   * {@link org.xml.sax.helpers.DefaultHandler}.
                   * @param inputstream InputStream containing the content to be parsed.
                   * @param cobject The SAX DefaultHandler to use.
                   * @exception IOException If any IO errors occur.
                   * @exception IllegalArgumentException If the given InputStream is null.
                   * @exception SAXException If the underlying parser throws a
                   * SAXException while parsing.               
                   saxParser.parse(in, this);
                   System.out.println(sb.toString());
              catch (FactoryConfigurationError e)
                   e.printStackTrace();
              catch (ParserConfigurationException e)
                   e.printStackTrace();
              catch (SAXException e)
                   e.printStackTrace();
              catch (IOException e)
                   e.printStackTrace();
         public void startDocument()throws SAXException
         public void endDocument()throws SAXException
         public void startElement(String namespaceURI, String name, String qName, Attributes attrs)
         throws SAXException
              if(count == 1)
                   sb.append("<"+PREFIX+qName+" "+PREFIX+"xmlns="+namespaceURI+">");
              else
                   sb.append("<"+name+">");
              count ++;
         public void endElement(String uri, String name, String qName) throws SAXException
              sb.append("</"+qName+">");
         public void characters(char buf[], int offset, int len)
         throws SAXException
              String s = new String(buf, offset, len);
              buf  = null;
              sb.append(s.trim());
                   s = null;
    Regards
    Fariha

  • Problem in SAX Java mapping

    Hi,
    I'm using SAX Java mapping in one scenario. Problem is when I get some Croatina characters, like Đ or u0160,
    output XML is not valid. XML Spy complains, IE complains and so on. Customer is sure  that data ( XML in CLOB field in Oracle DB) is UTF-8? What could be a problem?
    What I'm doing is reading entire XML into string with help of BufferedReader, then do some manipulation and write String into byte array with:
                   byte[] bytes = file.toString().getBytes("UTF-8");
                   saxParser.parse(new ByteArrayInputStream(bytes), handler);
    and then of course parse XML. readLine method reads data and problematic is "Ä�" - ￯0 - 0xC490.
    For this character XML Spy doesn't complain, IE also. After conversion, this character looks like "Ä?" - 0xC43F, and this is not good any more. Why?

    Hi Stefan,
    I've finally done it. Code as foollws:
         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();
                   fStreamOut = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
                   encoding = "UTF-8";
                   if (map != null) {
                        mappingTrace = (MappingTrace) map
                                  .get(StreamTransformationConstants.MAPPING_TRACE);
                   InputStreamReader is = new InputStreamReader(in, "UTF8");
                   BufferedReader reader = new BufferedReader(is);
                   StringBuffer file = new StringBuffer();
                   String line = new String();
                   try {
                        while ((line = reader.readLine()) != null) {
                             file.append(line);
                   } catch (IOException e) {
                        e.printStackTrace();
                   } finally {
                        try {
                             in.close();
                        } catch (IOException e) {
                             e.printStackTrace();
                   Date d4 = new Date();
                   file = replaceREGEX(
                             "<\\?xml version=\"1\\.0\" encoding=\"UTF-8\"\\?>", "",
                             file);
                   char[] cArray = file.toString().toCharArray();
                   Date filedat = new Date();;
                   SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
                   String fName = df.format(filedat) + "_El_Invoice.xml";
                   Writer out1 = new BufferedWriter(new OutputStreamWriter(
                             new FileOutputStream(fName), "UTF8"));
                   try {
                        out1.write(file.toString().toCharArray());
                        out1.close();
                   } catch (UnsupportedEncodingException e) {
                   } catch (IOException e) {
                   saxParser.parse(fName, handler);
                   File outFile = new File(fName);
                   outFile.delete();
              } catch (Throwable t) {
                   if (mappingTrace != null) {
                        mappingTrace.addInfo(t.toString());
                   t.printStackTrace();
    problem was also in method for writing in output stream, so I've changed it:
         private void printOutPut(String sOP) {
              try {
                      //    fStreamOut.write(sOP.getBytes());
                   fStreamOut.write(sOP);
              } catch (IOException e) {
                   e.notify();

  • Context change by DOM parsing Java Mapping in XI

    Hi Team,
    I would like to know that how can I handle Context Change by DOM Parser Java Mapping in XI.?
    Suppose  the source XML structure I have like below:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Header xmlns:ns0="urn:bp:xi:hr:edm:test:100">
       <FileName>
          <filesub>
             <subname>a</subname>
             <subname>b</subname>
             <subname>c</subname>
          </filesub>
       </FileName>
       <FileName>
          <filesub>
             <subname>d</subname>
             <subname>e</subname>
             <subname>f</subname>
          </filesub>
       </FileName>
    </ns0:Header>
    Where the field FileName can occur maximum thrice(0...3) but the subname field is (0....unbounded) but in the target source I would like to have as given below:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <MT_Test4 xmlns="urn:bp:xi:hr:edm:test:100">
    - <Header>
      <FileName>a</FileName>
      <FileName1>d</FileName1>
        </Header>
    - <Header>
      <FileName>b</FileName>
      <FileName1>e</FileName1>
       </Header>
    Header>
      <FileName>c</FileName>
      <FileName1>f</FileName1>
       </Header>
    </MT_Test4>
    That means the first value from every context of the source field is forming my first and second value in my target first context.Thensecond value from every context is forming my 1st and 2nd value of my target 2nd context and finally 3rd value of every context is forming my 1st and 2nd value of my target 3rd context.Is this possible to done through DOM parsing or we have to do it by UDF only?

    Hi Atanu,
        In my last post I gave an alogorithm to solve the mapping problem. Here is the complete program for the mapping.
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    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.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 com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    public class DOMParser1  implements StreamTransformation{
         public void execute(InputStream in, OutputStream out)
                   throws StreamTransformationException {
              try
                   DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
                   DocumentBuilder builderel=factory.newDocumentBuilder();
                   /input document in form of XML/
                   Document docIn=builderel.parse(in);
                   /document after parsing/
                   Document docOut=builderel.newDocument();
                   TransformerFactory tf=TransformerFactory.newInstance();
                   Transformer transform=tf.newTransformer();
                   Element root,child,child1=null;
                   Node textChild;
                   NodeList l;
                   int i,n1,j,div,k;
                   String s[];
                   root=docOut.createElement("MT_Test4");
                   root.setAttribute("xmlns","urn:bp:xi:hr:edm:test:100");
                   l=docIn.getElementsByTagName("subname");
                   n1=l.getLength();
                   s=new String[n1];
                   for(i=0;i<n1;++i)
                             s<i>=l.item(i).getFirstChild().getNodeValue();
                   l=docIn.getElementsByTagName("filesub");
                   div=l.getLength();
                   j=n1/div;
                   for(i=0,k=0;i<j;++i)
                        child1=docOut.createElement("Header");
                        root.appendChild(child1);
                        child=docOut.createElement("FileName");
                        textChild=docOut.createTextNode(s[k]);
                        child.appendChild(textChild);
                        child1.appendChild(child);
                        child=docOut.createElement("FileName1");
                        textChild=docOut.createTextNode(s [ k + j ]);
                        child.appendChild(textChild);
                        child1.appendChild(child);
                        ++k;
                   docOut.appendChild(root);
                   transform.transform(new DOMSource(docOut), new StreamResult(out));     
              catch(Exception e)
                   e.printStackTrace();
         public void setParameter(Map arg0) {
         public static void main(String[] args) {
              try{
                   DOMParser1 genFormat=new DOMParser1();
                   FileInputStream in=new FileInputStream("C:/Apps/my dw/sdnq/apps.xml");
                   FileOutputStream out=new FileOutputStream("C:/Apps/my dw/sdnq/tgt1.xml");
                   genFormat.execute(in,out);
              catch(Exception e)
                   e.printStackTrace();
    source ->  apps.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:Header xmlns:ns0="urn:bp:xi:hr:edm:test:100">
    - <FileName>
    - <filesub>
      <subname>a</subname>
      <subname>b</subname>
      <subname>c</subname>
      </filesub>
      </FileName>
    - <FileName>
    - <filesub>
      <subname>d</subname>
      <subname>e</subname>
      <subname>f</subname>
      </filesub>
      </FileName>
      </ns0:Header>
    target structure ->  tgt1.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    - <MT_Test4 xmlns="urn:bp:xi:hr:edm:test:100">
    - <Header>
      <FileName>a</FileName>
      <FileName1>d</FileName1>
      </Header>
    - <Header>
      <FileName>b</FileName>
      <FileName1>e</FileName1>
      </Header>
    - <Header>
      <FileName>c</FileName>
      <FileName1>f</FileName1>
      </Header>
      </MT_Test4>
    Hope this helps
    one more thing  in this line "textChild=docOut.createTextNode(s k + j );"   somehow the the third braces one opening  before k and one closing after j is missing for unknown reasons. Please correct it when you actually run this code.
    regards
    Anupam
    Edited by: anupamsap on Mar 7, 2011 12:47 PM

  • JAVA Mapping: Convert a W3C DOM into OutputStream

    hi everybody,
    how do I convert a org.w3c.dom.Document into outputStream as needed in JAVA mapping?
    Thanks regards
    Mario

    Hi Mario,
    even if you already found the solution, I think the information may be useful to others.
    You could do something like:
    import org.w3c.dom.Document;
    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.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    Document doc;
    try {
         TransformerFactory tf = TransformerFactory.newInstance();
         Transformer trans = tf.newTransformer();
         trans.transform(new DOMSource(doc), new StreamResult(out));
    } catch (TransformerConfigurationException e) {
         // Implement exception handling
    } catch (TransformerException e) {
         // Implement exception handling
    Regards,
    Henrique.

  • JAVA Mapping with SAX: Illegal character exception &

    Hi everybody,
    I use a SAX JAVA Mapping. It throws an error cause the xml that is parsed has a
    &amp;
    like in
    <D_3036>Company &amp; Co. KG</D_3036>
    Does anybody know how to solve the problem?
    I do not want to replace the
    &amp;
    Are there special settings/properties for the handler/parser?
    Thanks
    Regards
    Mario

    Hi all,
    thanks for your comments and suggestions. The error was not cause by the problem I describes.
    FYI:
    If there is an ampersand in the middle of a string, than the standard method
    characters
    in the handler is called three times!
    This let me asume the ampersand was the error.
    Regards Mario
    Edited by: Mario Müller on Dec 19, 2008 1:23 AM

  • JAVA Mapping (DOM)

    Hi Guys,
    Can i test my JAVA Mapping (DOM).
    I create all coding as per the requirment . Is it a way that in the NWDS in can give input XML Document and test there in Eclipse before am using it in the XI Mapping.
    How to pass "InputStream in" XML document and read the output.
    Am bit new to JAVA programing.
    If there is anyu way plz do provide me an idea , that help me in debigging well my JAVA Programing
    regards
    Srinivas

    hi venkateshwarulu
    check the below blogs
    XI Java Mapping Helper (DOM)                              
    The specified item was not found.                         
    Think objects when creating Java mappings                              
    Think objects when creating Java mappings                         
    Testing and Debugging Java Mapping                              
    Testing and Debugging Java Mapping in Developer Studio
    reward pionts if helpfull
    regards
    kummari
    Edited by: kummari on Jul 9, 2008 7:28 AM
    Edited by: kummari on Jul 9, 2008 7:51 AM

  • XI java mapping using SAX

    Hi,
    im using java mapping for complex IDOC structure. If I run program localy, it works great, but when XI runs mapping, I have problems with xml file, some elements are not there ?! I don't know why it happens.....i said that i'm using complex logic, and therefore I'm using complex IF statments to produce segment in IDOC. I have noticed that there is a problem, because when I switch off IF, everything is fine???? any idea??
    thx mario

    Hi,
    Do you have nested 'if' statements?  Is it possible you could be experiencing a "dangling else" problem?
    http://www.dai-arc.polito.it/dai-arc/manual/tools/jcat/main/node101.html

  • JAVA mapping error

    Hi All,
    I am getting the below error while executing a JAVA mapping.
    <SAP:Category>Application</SAP:Category>
      <SAP:Code area="MAPPING">LINKAGE_ERROR</SAP:Code>
      <SAP:P1>XMLNSTagCreate1/XMLNSTagCreate1</SAP:P1>
      <SAP:P2>java.lang.NoClassDefFoundError: XMLNSTagCreate1/XM</SAP:P2>
      <SAP:P3>LNSTagCreate1 (wrong name: XMLNSTagCreate1)</SAP:P3>
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:Stack>Linkage error while loading class XMLNSTagCreate1/XMLNSTagCreate1; java.lang.NoClassDefFoundError: XMLNSTagCreate1/XMLNSTagCreate1 (wrong name: XMLNSTagCreate1)</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
    I have tried compiling the code in the same JRE as the one in PI. Still it is not working.
    Please suggest.
    Regards,
    Yashwanth
    Edited by: YashwanthSVK on Aug 17, 2011 8:38 PM

    Hi all... thank you for the replies.. I have compiled the code in the same version of JRE as the PI version...
    Hi Vijay,
    I also felt the same but as I do not have much knowledge in JAVA, i could not track it further. 
    below is the code for the mapping... would you mind if I ask you to have a look at it and let me know where the error is..
    thank you so much ...
    import java.io.*;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.TransformerFactory;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    import com.sap.aii.mapping.api.MappingTrace;
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import javax.xml.transform.OutputKeys;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactoryConfigurationError;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import java.io.FileWriter;
    This mapping creates xmlns attribute to send to Tradeplace
    public class XMLNSTagCreate1 extends DefaultHandler  implements StreamTransformation {
         private Map param;
         private MappingTrace trace;
         private OutputStream out;
         public void execute(InputStream in, OutputStream out)
              throws StreamTransformationException {
                   DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
                        try {
                             //trace.addWarning("Execute function starts here");
                             DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
                             try {
                                  org.w3c.dom.Document doc = docBuilder.parse(in);
                                  //Node TradeplaceMessage = doc.getFirstChild();
                                  Element trade=(Element) doc.getFirstChild();
                                  if(trade.hasAttribute("tag1"))
                                  NamedNodeMap TradeplaceMessageAttributes = trade.getAttributes();
                                  String xmlnsValue=trade.getAttribute("tag1");
                                  String modeValue=trade.getAttribute("productionMode");
                                      trace.addInfo("XMLNS  Value:"+xmlnsValue);
                                                                     trade.removeAttribute("tag1");
                                       trade.removeAttribute("productionMode");
                                       trade.setAttribute("xmlns",xmlnsValue);
                                       trade.setAttribute("productionMode",modeValue);
                                                      javax.xml.transform.Transformer transformer = TransformerFactory.newInstance().newTransformer();
                                                      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                                                      StreamResult result = new StreamResult(new StringWriter());
                                                      DOMSource source = new DOMSource(doc);
                                                      transformer.transform(source, result);
                                                      String xmlString = result.getWriter().toString();
                                                      //System.out.println(xmlString);
                                                      out.write(xmlString.getBytes());
                             } catch (SAXException e1) {
                                  // TODO Auto-generated catch block
                                  e1.printStackTrace();
                             } catch (IOException e1) {
                                  // TODO Auto-generated catch block
                                  e1.printStackTrace();
                             } catch (TransformerConfigurationException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                             } catch (TransformerFactoryConfigurationError e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                             } catch (TransformerException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                        } catch (ParserConfigurationException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
         public static void main2(String[] args) throws Exception {
              String xmlFile = "U:
    Untitled.xml";
              InputStream in = new BufferedInputStream(new FileInputStream(xmlFile));
              XMLNSTagCreate1 test = new XMLNSTagCreate1();
              //test.countOccurences(in);
         public static void main(String[] args) throws Exception {
              String xmlFile = "//NA.AD.WHIRLPOOL.COM//myApps//home//NA//qqjos1d//My Documents//TP2.xml";
              InputStream in = new BufferedInputStream(new FileInputStream(xmlFile));
              FileOutputStream out = new FileOutputStream("//NA.AD.WHIRLPOOL.COM//myApps//home//NA//qqjos1d//My Documents//DhanishTP2.xml");
              XMLNSTagCreate1 test = new XMLNSTagCreate1();
              test.execute(in, out);
              OutputStreamWriter out1 = new OutputStreamWriter(out,"UTF-8");
         /* (non-Javadoc)
    @see com.sap.aii.mapping.api.StreamTransformation#setParameter(java.util.Map)
         public void setParameter(Map param) {
              // TODO Auto-generated method stub

  • XML - SAX or DOM?

    Hi folks,
    I'm on the verge of emotional breakdown trying to get my head around working with XML in Java, and I would really appreciate a bit of help.
    What I would like to do is to store database metadata in an XML file.
    The steps I have taken so far are to read the metadata into a structure of objects (a metadata object that containts arraylists of tables objects that contain arraylists of columns object. Each of these object types holds information about the table or column concerned (table name, column type etc).
    I'm stuck when it comes to deciding whether to use SAX or DOM to write / read these files.
    Now, I understand that SAX is for sequential access, and DOM is for situations where you'd like to manipulate the XML tree. I guess that, given the nature of my data structure DOM would make more sense? Then I can define a node for each table, then off them, define a node for each column... Or am I missing the point here?
    Can anyone give me a nudge in the right direction?
    Thanks in advance
    s.

    Thanks for replying!
    Duffymo, I'd rather keep the xml content to the data
    to make the files easy to edit / write by hand.Not following you here.
    I understand that you want XML files, but XStream can take them and turn them into Java objects for you. Conversely, you can take a graph of Java objects and serialize them as XML.
    No worries about DOM or SAX that way.
    %

Maybe you are looking for

  • Can not do Surrogate bidding after Bid invitaion End date has been reached

    We are on SRM 5 server 5.5 We are using surrogate bidding to capture  bid responses and we manually receive vendors responses by the End date on the Bid invitation . We are unable to do surrogate bidding after the End date has been reached hence we t

  • Do I need to buy an ethernet switch that has a WAN port

    I want to buy an Aiport Express to handle a WiFi only iPad and an old PPC iMac with 10.5.8 on it that has no WiFi card.  The iMac gets on the internet from a cable plugged directly into its ethernet port (using DHCP).  The cable comes off an antenna

  • Why won't my folders in finder expand in the icon view?

    My folders will not expand in the icon view in finder. They also don't expand in the cover flow view, only list and column view show the contents within folders. It's affecting all the items in finder's sidebar. I found this rather bizarre. Has any o

  • Enabling eRecord for standard WIPMOVE in the custom form using wip interfac

    Hi, Anyone know how to trigger the eRecord for the standard WIPMOVE transaction in the custom form using WIP Interface (wip_move_txn_interface & wip_movproc_pub.processinterface). I have done all the necessary setting and eRecords is getting generate

  • Trigger function when loaded swf finishes

    I'm making a site that loads external swfs based on which button is clicked. When the swf loads it plays an intro and then stops at a certain point. My goal is that when you click another button the current swf plays an outro before the next one load