13 Replies Latest reply: Jan 20, 2010 10:13 PM by Shamly MM RSS

Add XML header?

Shamly MM
Currently Being Moderated

Hi Experts ,

 

I need to add this extra 2nd line in my generated xml output of graphical mapping.

 

<?xml version="1.0" encoding="UTF-8"?>

<?Siebel-Property-Set EscapeNames="false"?>

 

Is there any smart way to add this 2nd line? I have already created a graphical mapping for the message with complex lookups and do not wish change it much.

 

Thanks

Shamly.

  • Re: Add XML header?
    Udo Martens
    Currently Being Moderated

    Hi Shamly,

     

    you can achieve that very smart with a second, non parsing ABAP mapping:

     

    -use fm ECATT_CONV_XSTRING_TO_STRING to convert the source to string,

    - search for "<?Siebel-Property-Set EscapeNames="false"?>"

    - concatenate the  both header and the xml payload

    - use fm ECATT_CONV_STRING_TO_XSTRING to convert the string to result (XSTRING)

     

    just a view lines,

     

    Regards,

    Udo

  • Re: Add XML header?
    Shabarish Vijayakumar
    Currently Being Moderated

    my suggestion is a simple java mapping and use normal string functions to achieve the result

    • Re: Add XML header?
      Shamly MM
      Currently Being Moderated

      Hi ,

       

      I am tryin to achieve it with java mapping.

      With what ext do you save the java code? I am trying to upload it to the operation mapping as the second mapping, but it is giving the error that the file does not contain a java program.

       

      Thanks,

       

      Shamly

      • Re: Add XML header?
        abhishek salvi
        Currently Being Moderated

        You first write the java logic and store it in a .java file, then you compile this .java fiel and on proper compilation you get a .class file.......you can include this .class file into IR .... NWDS can be used in this case.

         

        Regards,

        Abhishek.

        • Re: Add XML header?
          Shamly MM
          Currently Being Moderated

          Hi experts,

           

          I am using the shabarish' blog

           

          /people/shabarish.vijayakumar/blog/2009/12/07/parametrized-java-mapping-in-pi-71-plus-some-other-delicacies

           

          i am using the reference java code given within

          http://wiki.sdn.sap.com/wiki/display/XI/ParametrizedJavaMappinginPI+7.1

           

           

          I have copied the code and trying to compile it in eclipse.

          This is giving me lot of error messages in eclipse - like- import com.sap cannot be resolved.

           

          and it is generating a number of class files.

           

          Can these errors be ignored?

          Do i need to import all the class files created?

           

          Thanks,

          Shamly

          • Re: Add XML header?
            Swetha Reddy
            Currently Being Moderated

            Hi,

             

            Those errors are cannot be ignored.

            For java mapping, you have to import the jars below..

             

            com.sap.aii.af.cpa.svc.api

            com.sap.aii.af.lib.mod

            com.sap.aii.af.ms.ifc_api

            com.sap.aii.af.svc_api

            com.sap.xpi.ib.mapping.lib

            sap.comtcloggingjavaimpl

             

             

            Regards,

            Swetha.

             

            Edited by: Swetha Reddy on Jan 13, 2010 10:17 AM

      • Re: Add XML header?
        Fariha Ali
        Currently Being Moderated

        Check if the java mapping thing works (when the xml has completed its java mapping part , the next steps may enforce the tag to be ignored ).

        This happened to me when i tried inserting < ! -- />  tag.

         

        So finally I was required to create an adapter module (which is the last phase of processing ) for inserting the tag.

  • Re: Add XML header?
    Raghu Vamseedhar Reddy Kadipi Reddy
    Currently Being Moderated

    Hi Shamly,

     

    You are on right path.

    Use your graphical mapping (for complex lookup and other logic) after that use another Java Mapping ( to add <?  ?> line) in Operational Mapping.

     

    Use this bolg to develop Java Mapping /people/carlosivan.prietorubio/blog/2007/12/21/implementing-a-java-mapping-in-sap-pi

     

    Hope this code will help you

     

    import java.io.*;

    import java.util.*;

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

     

    public class DynamicMapping implements StreamTransformation {

     

        private Map param;

     

        public void setParameter(Map param) {

            this.param = param;

        }

     

        public void execute(InputStream in, OutputStream out) throws StreamTransformationException {

            try {

              byte[] b = new byte [in. available ()]; //  in.available() is in square brackets

                            in.read(b);

              StringBuffer input = new StringBuffer( new String(b));

                            /*note         "   '  '   "       in double Quotes  we can have single Quotes.

                            /Here we are inserting <?Siebel-Property-Set EscapeNames='false'?>  after <?xml version="1.0" encoding="UTF-8"?> i.e after ?> */

              input.insert(input.indexOf("?>")+2, "<?Siebel-Property-Set EscapeNames='false'?>");

                           out.write(b.toString().getBytes()); 

            } catch (IOException ex) {

               ex.printStackTrace();

            }

        }

    }

     

    Edited by: Raghu Vamsee on Jan 13, 2010 7:22 PM

  • Re: Add XML header?
    Anshul Chowdhary
    Currently Being Moderated

    Hi,

     

    I guess you can also do this by using a simple XSLT mapping after your grphical in the operation mapping. The cod efor the same is as given below:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

     

    <!-- Add the your desired field -->

    <xsl:output method="xml" indent="no" omit-xml-declaration="no"

    Siebel-Property-Set EscapeNames="false"/>

     

    <!-- Identity Transform - copy the source XML to the output without any changes -->

    <xsl:template match="node() | @*">

    <xsl:copy>

    <xsl:apply-templates select="node() | @*"/>

    </xsl:copy>

    </xsl:template>

    </xsl:stylesheet>

     

    Warm Regards,

    Anshul

  • Re: Add XML header?
    Shamly MM
    Currently Being Moderated

    Thank you very much for your answers and suggestions following which i got the desired result.

     

    I used , second java mapping and compiled the code with NWDS.

Actions