cancel
Showing results for 
Search instead for 
Did you mean: 

<?xml...................standalone="yes"?>

mayur_patel6
Participant
0 Kudos

Hello Experts, I have a RFC -> JMS scenario where I need to add standalone="yes"? into an inbound XML from RFC, before it hits the mapping.

So, right now the XML that I am getting from RFC looks like this ...

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

And, I want to add standloan attribute to my xml before it goes in my graphical mapping. So, i need to make it this (below) somewhere between RFC and Graphical mapping

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

Thanks,

Mayur

Accepted Solutions (0)

Answers (1)

Answers (1)

stefan_grube
Active Contributor
0 Kudos

>. So, i need to make it this (below) somewhere between RFC and Graphical mapping

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

You can use XSLT as first mapping step.

Just for curiosity, can you tell me, why you want to do this?

mayur_patel6
Participant
0 Kudos

Thanks.

Basically, xml parser in the legacy system is expecting this standalone attribuite to be there otherwise it throws an error. I'll try XSLT.

Thanks,

Mayur

stefan_grube
Active Contributor
0 Kudos

> Basically, xml parser in the legacy system is expecting this standalone attribuite to be there otherwise it throws an error. I'll try XSLT.

In that case, you should do this after the graphical mapping tool.

If you know Java, you can use Java mapping. Just a simple String manipulation.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Mayur,

I am not sure if with XSLT mapping you will be able to include standalone attribute in target XML. With java mapping it becomes very easy. Here are java mapping codes.

For PI 7.0


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;


import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;


public class addAttributeToTag1 implements StreamTransformation {

	/**
	 * @param args
	 */
	

	public void execute(InputStream in, OutputStream out)
			throws StreamTransformationException {
		// TODO Auto-generated method stub
		try
		{
			int c;
			int count=0;
			while(1>0)
			{	
				
				c=in.read();
				if(c<0)
				{
					break;
				}
				if((char)c=='?')
				{
					count++;
				}
				if(count==2)
				{
					out.write(" standalone=\"no\" ".getBytes());
					count=3;
				}
				out.write(c);
				
			}
			in.close();
			out.close();
		}	
		catch(Exception e)
		{
		}	
		
	}

	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			addAttributeToTag1 genFormat=new addAttributeToTag1();
			FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\copy.xml");
			FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\copy1.xml");
			genFormat.execute(in,out);
			}
			catch(Exception e)
			{
			e.printStackTrace();
			}
	}
}


For PI 7.1 and above


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;





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;


public class addAttributeToTag extends AbstractTransformation {

	/**
	 * @param args
	 */
	

	public void execute(InputStream in, OutputStream out)
			throws StreamTransformationException {
		// TODO Auto-generated method stub
		try
		{
			int c;
			int count=0;
			while(1>0)
			{	
				
				c=in.read();
				if(c<0)
				{
					break;
				}
				if((char)c=='?')
				{
					count++;
				}
				if(count==2)
				{
					out.write(" standalone=\"no\" ".getBytes());
					count=3;
				}
				out.write(c);
			
			}
			in.close();
			out.close();
		}	
		catch(Exception e)
		{
		}	
		
	}

	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}
	public void transform(TransformationInput arg0, TransformationOutput arg1)
	throws StreamTransformationException {
// TODO Auto-generated method stub
		this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			addAttributeToTag genFormat=new addAttributeToTag();
			FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\copy.xml");
			FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\copy1.xml");
			genFormat.execute(in,out);
			}
			catch(Exception e)
			{
			e.printStackTrace();
			}
	}

	
	
}

Please Use this java mapping code after graphical mapping in the same Interface mapping.

Few blogs on java mapping which might be of some help

http://wiki.sdn.sap.com/wiki/display/XI/SampleJAVAMappingcodeusingPI7.1+API

http://wiki.sdn.sap.com/wiki/display/XI/UsingPI7.1APIforJavamapping

http://www.objectbiz.com/post/5249313454/sap-pi-java-mapping-from-7-0-to-7-1

http://wiki.sdn.sap.com/wiki/display/XI/BeginnersguidetoJavamappingusingDOMparserinSAPXI

_______________________________________________________________________________________________________

Hi Mayur,

Did this mapping code help solve your problem? One small request, if you think forum members have answered your queries correctly, Could you please kindly, if possible close the threads you are opening. This is important because it helps people who look for solutions to similar problems in future and they know for sure that the solution has worked.

_______________________________________________________________________________________________________

regards

Anupam

Edited by: anupamsap on Oct 8, 2011 10:48 PM

Edited by: anupamsap on Oct 12, 2011 8:42 AM

Edited by: anupamsap on Oct 26, 2011 5:33 AM