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

Similar Messages

  • Context change

    Hi,
    what is context change?? where it is implemented?
    thanks in advance.

    Hi!
    Context changes take place in Message Mapping when the source structure is processed. for more details about mapping and context change see sap online help - e.g. here http://help.sap.com/saphelp_nwpi71/helpdata/en/49/1ebc6111ea2f45a9946c702b685299/content.htm
    Regards,
    Volker
    Additionally:
    More detailed information about contexts and context changes see here: http://help.sap.com/saphelp_nwpi71/helpdata/en/3d/24e15bf9d79243b45d49b13b03de8f/content.htm
    Edited by: Volker Kolberg on May 25, 2009 10:10 AM

  • How to manipulate object mapping runtime using DOM parser in java?

    Scenario: We will be getting logical name of the table from which we have to fetch the details. We have few tables which have more or less same columns, the only difference is the prefix. Say we have Tables: Temp1 and Temp2 contains column as Temp1Col1 and Temp2Col1. I dont want to go with creating as many POJO classes in java as that of tables. So i will create only one POJO class with common attributes and at runtime i want to change the object mapping file of Hibernate to hold table values. I have an idea that this can be done using DOM parser. But it would be great if somebody can share the java code for the same.
    Thanks in advance.

    SAX is a parser, not a generator.Well,
    you can use it to create an XML file too. And it will take care of proper encoding, thus being much superior to a normal textwriter:
    See the following code snippet (out is a OutputStream):
    PrintWriter pw = new PrintWriter(out);
          StreamResult streamResult = new StreamResult(pw);
          SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
          //      SAX2.0 ContentHandler.
          TransformerHandler hd = tf.newTransformerHandler();
          Transformer serializer = hd.getTransformer();
          serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"pdfBookmarks.xsd");
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://schema.inplus.de/pdf/1.0");
          serializer.setOutputProperty(OutputKeys.METHOD,"xml");
          serializer.setOutputProperty(OutputKeys.INDENT, "yes");
          hd.setResult(streamResult);
          hd.startDocument();
          //Get a processing instruction
          hd.processingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"mystyle.xsl\"");
          AttributesImpl atts = new AttributesImpl();
          atts.addAttribute("", "", "someattribute", "CDATA", "test");
          atts.addAttribute("", "", "moreattributes", "CDATA", "test2");
           hd.startElement("", "", "MyTag", atts);
    String curTitle = "Something inside a tag";
              hd.characters(curTitle.toCharArray(), 0, curTitle.length());
        hd.endElement("", "", "MyTag");
          hd.endDocument();
    You are responsible for proper nesting. SAX takes care of encoding.
    Hth
    ;-) stw

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

  • 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>

  • 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

  • Getting Error in java mapping: Parsing empty source. Root element expected!

    Hi Experts,
       I am using java mapping for schema validation of input message. I have followed all the standard procedures and implemented the java class in the interface mapping.
    My interface mapping is like this:
    OrderData --->Java Class ---SchemaValidate
                         Mesg Map ---OrderData_to_BAP --->BAPI Msg
    So first I want to validate the schema of the input message. If the input message is invalid then XI should throw an exception. Then I use the actual message mapping to map the input order data to the BAPI input parameters.
    In the java code I am using xerces parser.
    The java code works fine when I run it as a standalone application.
    The interface mapping also works fine if I don't include the java mapping. Ofcourse schema validation does not happen.
    But when I test the interface mapping by including the java mapping then I am getting the error:
    Call method execute of the application Java mapping SchemaValidate
    Java mapping SchemaValidate completed. (execute() of SchemaValidate
    com.sap.aii.utilxi.misc.api.BaseRuntimeException: Parsing an empty source. Root element expected!
    What am I doing wrong? Why it is not getting the root element?
    My Java code is as follows:
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationConstants;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import java.io.*;
    import java.util.Map;
    import javax.xml.parsers.*;
    import org.xml.sax.helpers.*;
    import org.xml.sax.*;
    import org.apache.xerces.jaxp.*;
    Sample mapper for SAP-XI
    @author Gopal
    public class SchemaValidate implements StreamTransformation {
        //Constants when using XML Schema for SAX parsing.
         static final String JAXP_SCHEMA_LANGUAGE =
         "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
         static final String W3C_XML_SCHEMA =
         "http://www.w3.org/2001/XMLSchema";
         static final String JAXP_SCHEMA_SOURCE =
         "http://java.sun.com/xml/jaxp/properties/schemaSource";
    Injection of mapping parameters
    from integration engine
    @param map Map with configuration data
        public void setParameter(Map map) {
    Mapping implementation
    @param inputStream Input data from integration engine
    @param outputStream Output data to integration engine
        public void execute(InputStream inputStream,
                            OutputStream outputStream)
          throws StreamTransformationException {
            try {
                  // obtain an object of class javax.xml.parsers.SAXParser,
                  SAXParserFactory spf = SAXParserFactoryImpl.newInstance();
                  spf.setNamespaceAware(true);
                  spf.setValidating(true);
                  SAXParser sp = spf.newSAXParser();
                  // setup the schema file
                  sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                  sp.setProperty(JAXP_SCHEMA_SOURCE, new File("IOReqMsgSchema.xsd"));
                  //parse the input xml using the given schema
                  sp.parse(inputStream, new ParseErrorHandler());
            catch(SAXException se) {
              se.printStackTrace();
            catch ( Exception e ) {
              throw new StreamTransformationException( e.getMessage() );
    My input message is :
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:OrderCreate_request xmlns:ns0="mynamespace">
       <ORDER>HTEST1234567</ORDER>
       <ORDER_TYPE>z001</ORDER_TYPE>
       <ORDER_NAME>Test Order</ORDER_NAME>
       <CO_AREA>INTC</CO_AREA>
       <CCTR_POSTED>1234567890888888888</CCTR_POSTED>
       <CURRENCY>USD</CURRENCY>
       <PERSON_RESP>12345679</PERSON_RESP>
    </ns0:OrderCreate_request>
    Kindly help! please this is urgent!!!!!!
    Thanks
    Gopal
    Edited by: gopalkrishna baliga on Feb 28, 2008 9:34 AM

    Hi Stefan,
       I did the code changes to return output stream and the java code works perfectly in standalone mode in my PC.
       But when I use the same in the Java mapping with XI then It throws an error "Getting Error in java mapping: Parsing empty source. Root element expected!".
    My XI J2EE server has JDK1.4.3.11.
    Is there any limitation of using SAX parser in XI? If Yes, then which parser should be used for schema validation in XI?
    I have included the XSD file for schema validation along with class files in the .jar file. This jar file is then imported in XI repository. Is the XI engine not able to read the XSD file?
    Do I have to handle reading XSD file differently? Any suggession how?
    Is this parser error due to some security access?
    Kindly help me! I have been struggling with this problem since 2 weeks. I will be greatfull to you if you can help me.
    Thanks
    Gopal

  • Parsing an XML using DOM parser in Java in Recursive fashion

    I need to parse an XML using DOM parser in Java. New tags can be added to the XML in future. Code should be written in such a way that even with new tags added there should not be any code change. I felt that parsing the XML recursively can solve this problem. Can any one please share sample Java code that parses XML recursively. Thanks in Advance.

    Actually, if you are planning to use DOM then you will be doing that task after you parse the data. But anyway, have you read any tutorials or books about how to process XML in Java? If not, my suggestion would be to start by doing that. You cannot learn that by fishing on forums. Try this one for example:
    http://www.cafeconleche.org/books/xmljava/chapters/index.html

  • 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 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 - for reading the binary file contents and changing filename

    Hi,
    I have already gone through the various bolgs and threads and have not been able to find a solution to my problem.
    One blog did give some idea but did not help- "JAAPPING", an alternate way of reading a CSV file
    I am not very good in java but have been trying some out recently to fulfill the interface requirements.
    I would really appreciate if you could help am I am giving below the detailed scenario below.
    Part 1- working fine - The incoming file looks like:
    :20:STMEMU096868DUBE
    :25:001180256210
    :28C:00371/00001
    :60F:C090617AED742136,92
    :61:0906300630CD34,27FINTCREDIT INTEREST
    26MAY2009 TO 25JUN2009
    :62F:C090630AED742171,19
    :64:C090630AED742171,19
    The file name as received is:TCDE.BLQSAM.SAEA2682.C0084025.A9G24T58.20090724195908
    This file without any conversion is placed on XI server dircetory folder.
    Part 2 - need to develop
    The file should now be renamed according to the incoming value in 2nd line - specifically the 12 digit value 001180256210 and placed on the R/3 dircetory folder.
    The new file name in the above example should be:
    AC_NO_001180256210_datetime
    The module for the above was created and the last time I checked it was working.
    However, when I wanted to do final testing in Dev and move the changes further, the module has seemed to have stopped working so I need an alternate solution fast.
    I was thinking of doing the Java mapping as I will be more in control as to what is going on thereby reducing the dependency.
    There is no need to create any target xml structure as the file as it is needs to be placed in the target folder with a new name.
    I can get the file name in UDF which I have already created but i am not usre if it working.
    Can you please help?
    Any help will be greatly appreciated.
    Regards,
    Archana
    +44-7867636863

    Hi Stephen
    The xml must be getting added in the below part of the code. It is coming from arg[0]
    You can put a check and get it removed.
    while ((len = arg0.read(buffer)) != -1) {
      arg1.write(buffer, 0, len);
    Regards
    Osman

  • Java DOM Parser (XML)

    Could someone please give me a link where I can find a example of a DOM parser, w3c. That shows how to parse an xml string or file and build the tree then access parts of it? I cant find a basic example anywhere!

    Check this
    http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/dom/1_read.html

  • Parsing xml using DOM parser in java

    hi there!!!
    i don have much idea about parsing xml.. i have an xml file which consists of details regarding indentation and spacing standards of C lang.. i need to read the file using DOM parser in java n store each of the attributes n elements in some data structure in java..
    need help as soon as possible!!!

    DOM is the easiest way to parse XML document, google for JDOM example it is very easy to implement.
    you need to know what is attribute, what is text content and what is Value in XML then easily you can parse your document with dom (watch for space[text#] in your XML document when you parse it).
    you get root node then nodelist of childs for root then go further inside, it is easy believe me.

  • 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.

  • Message Mapping - Initialize counter every context change

    Hi all,
    is there any way to develop a counter customer function in a graphical message mapping so every context change of a field the counter initializes?
    Imagine i have the following structure:
    1 DATA
    1.1 DETAIL
    1.2 DETAIL
    2 DATA
    2.1 DETAIL
    2.2 DETAIL
    and i wanna count DETAIL fields but initialize the counter every DATA field. Is there any way to do it?
    Thanks a lot.

    Hi,
    If your Source structure is
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
       <DATA>
          <DETAIL/>
          <DETAIL/>
       </DATA>
       <DATA>
          <DETAIL/>
          <DETAIL/>
          <DETAIL/>
       </DATA>
    </ns0:MT_DATA>
    and You want the Target as
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
       <DATA>
          <DETAIL>COUNTER=1</DETAIL>
          <DETAIL>COUNTER=2</DETAIL>
       </DATA>
       <DATA>
          <DETAIL>COUNTER=1</DETAIL>
          <DETAIL>COUNTER=2</DETAIL>
          <DETAIL>COUNTER=3</DETAIL>
       </DATA>
    </ns0:MT_DATA>
    Create the below UDF with one argument (DETAIL)  and select Execution type all values of a Context
    for (int i =1;i<=DETAIL.length;i++)
    result.addValue("COUNTER=" + i);
    but if you want Your Target as
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
       <DATA>
          <DETAIL>1</DETAIL>
          <DETAIL>2</DETAIL>
       </DATA>
       <DATA>
          <DETAIL>1</DETAIL>
          <DETAIL>2</DETAIL>
          <DETAIL>3</DETAIL>
       </DATA>
    </ns0:MT_DATA>
    So please Follow abhishek salvi's reply

Maybe you are looking for

  • Objects Creation

    Hi All, I created one string variable with null,and then i assign empty string("") to that variable . for instance String temp = null; temp = ""; temp = ""; for the above statements how many objects will be created . Thanks,

  • How do I fix my mac so that the window I am looking at has the focus?

    I am a new mac user and at present beyond comprehension of how people cope with mac if they are not primarily mouse oriented. Current problem. I close an app using apple key W It closes I am looking at a window of another app. I want to close that to

  • Issue After Rating setting is enabled to the Discussion Board List in SharePoint 2013.

    Hi , We are facing issues After Rating field is added to the Discussion Board List in SharePoint 2013. We are getting below error while adding a new item or editing a new item. Did anyone got this issue earlier and any solution for this. Ashish Kumar

  • PS E9 not recognized by image browser.

    I recently updated from PS E7 to E9. When using E7, my image browser (Nikon View NX2) worked properly. After installing E9, NX2 no longer connects to E9. When right clicking on an image in the browser, it gives ask for which program to open the image

  • Editor will not open.

    A little background. PSE 8 Windows 7 64 bit New computer. PSE 8 worked fine on old computer. A short time after installing PSE 8 on the new computer, photo email stopped working with a message that an email connection coould not complete. A few days