on 05-07-2010 9:35 AM
Hi,
I am creating a RFC - File scenario and i want the output file in XML format. So I m using "File" in the message protocol of the receiver file.
My output file structure format is as below:
<?xml version="1.0" encoding="UTF-8"?>
*<ns1:MT_LEBIZ xmlns:ns1="http://lebiz">*
<HEADER>
<CODE>TOT</CODE>
</HEADER>
<DETAILS>
<SEGMENT>
<NUMBER>01</NUMBER>
<LABEL>Account Assignment Cat</LABEL>
</SEGMENT>
<SEGMENT>
<NUMBER>02</NUMBER>
<LABEL>GL Account</LABEL>
</SEGMENT
</DETAILS>
</ns1:MT_LEBIZ>
but i wanted to display www3.org in the namespace in the following line which is marked in bold.
<ns1:MT_LEBIZ xmlns:ns1="http://lebiz">
how can i achieve that?
looking to change the namespace?
/people/shabarish.vijayakumar/blog/2010/05/07/quick-tips-dealing-with-namespaces-in-xipi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for the reply.
After re-assigning the MT in MM it worked.
But in the xml structure we actually want the tag like the following:
-<JEBIZ_HEADER xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
but we are getting as
<ns1:JEBIZ_HEADER xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">
how to remove "ns1" in the start of the tag and how to change xmlns:ns1 to xmlns:xsi.
We also need the xml structure in a tree like structure(which can be expanded & minimzed. but in our o/p file it doesnt show '-' in the header tag.
Hi
Use XmlAnonymizerbean adapter module in your receiver side.
/people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encoding-with-the-xmlanonymizerbean
https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=880173
Regards
Ramg
Hi,
but i am using a file adapter. can we use xml anonymizer bean in file adapter?
b'cos i tried adding values in Module configuration and it didnt work.
My requirement is :
<?xml version="1.0" ?>
- <JEBIZ_HEADER xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <HEADER>
<MINI_CODE>TOT</MINI_CODE>
<DEP_CODE>000</DEP_CODE>
<ENTITY_CODE>TOT~000</ENTITY_CODE>
<STATUS>NEW</STATUS>
</HEADER>
- <DETAILS>
- <SEGMENT>
<NUMBER>01</NUMBER>
<LABEL>Account Assignment Cat</LABEL>
</SEGMENT>
</JEBIZ_HEADER>
But my current payload looks like:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:JEBIZ_HEADER xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">
<HEADER>
<MINI_CODE>TOT</MINISTRY_CODE>
<DEP_CODE>000</DEPARTMENT_CODE>
<ENTITY_CODE>TOT</ENTITY_CODE>
<STATUS>NEW</STATUS>
</HEADER>
<DETAILS>
<SEGMENT>
<NUMBER>01</NUMBER>
<LABEL>Account Assignment Cat</LABEL>
</SEGMENT>
</ns1:JEBIZ_HEADER>
I have given the following in File Receiver C.C in module tab:
Processing sequence
AF_Modules/XMLAnonymizerBean Local Enterprise Bean 0
Module Configuration
0 anonymizer.acceptNamespaces http://www.w3.org/2001/XMLSchema-instance xsi
0 anonymizer.quote '
I also want to remove the encoding="UTF-8"? in xml tag, so if i try to give
0 anonymizer.encoding
its not working.
Kindly let me where i am wrong and whether i need to modify somewhere else as well.
Hi,
I m new to Java mapping and dont have Java knowledge. can you guide me where to start with for doing the Java mapping.
I have done the following. I have created a .class & .java file in my folder and moved it into a zip file. In the ESR, i have created Imported Archives and imported this zip file.
In operation mapping, in the mapping program i have selected Java class and included that zip file name.
My java code is :
import java.io.IOException;
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;
public class Test extends AbstractTransformation {
@SuppressWarnings("null")
public void transform(TransformationInput transformationInput,
TransformationOutput transformationOutput)
throws StreamTransformationException {
getTrace().addDebugMessage("Entered transform method");
InputStream in = transformationInput.getInputPayload().getInputStream();
OutputStream out = transformationOutput.getOutputPayload()
.getOutputStream();
try {
byte[] b = new bytehttp://in.available();
in.read(b);
String req = new String(b);
req = req.replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" , "<?xml version=\"1.0\"?>" );
out.write(req.getBytes());
out.flush();
}
catch (IOException ioe) {
getTrace().addWarning(
"Error While prerforming Java Transformation"
+ ioe.getMessage());
throw new StreamTransformationException(
"Error While prerforming Java Transformation"
+ ioe.getMessage(), ioe);
}
}
}
but when i execute the scenario, i m getting the following error:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <!-- Request Message Mapping
-->
- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
<SAP:Category>Application</SAP:Category>
<SAP:Code area="MAPPING">LINKAGE_ERROR</SAP:Code>
<SAP:P1>encode</SAP:P1>
<SAP:P2>java.lang.ClassFormatError: Incompatible magic val</SAP:P2>
<SAP:P3>ue 1768779887 in class file encode</SAP:P3>
<SAP:P4 />
<SAP:AdditionalText />
<SAP:Stack>Linkage error while loading class encode; java.lang.ClassFormatError: Incompatible magic value 1768779887 in class file encode</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
Hi,
i hope that we need to have JDK to write the Java code and import it in the operation mapping. so i have installed j2sdk1.4.2_15 and written a small java code in another folder. in the command prompt i am trying to execute the code using javac <pgm.java>.
if the code is compiled successfully then a .CLASS file also will be generated. so we have to move these .JAVA and .CLASS file into a ZIP folder and import it in the operation mapping.
pls let me know whether i m in the right path?
when i come the code which is given in the link it shows the following error:
C:\j2sdk1.4.2_15\java source>C:\j2sdk1.4.2_15\bin\javac getcontent.java
getcontent.java:8: package com.sap.aii.mapping.api does not exist
import com.sap.aii.mapping.api.AbstractTransformation;
^
getcontent.java:9: package com.sap.aii.mapping.api does not exist
import com.sap.aii.mapping.api.StreamTransformationException;
^
getcontent.java:10: package com.sap.aii.mapping.api does not exist
import com.sap.aii.mapping.api.TransformationInput;
^
getcontent.java:11: package com.sap.aii.mapping.api does not exist
import com.sap.aii.mapping.api.TransformationOutput;
^
getcontent.java:14: package com.sap.xpi.ib.mapping.lib does not exist
import com.sap.xpi.ib.mapping.lib.jar;
^
getcontent.java:17: cannot resolve symbol
symbol : class AbstractTransformation
location: class GetContent
public class GetContent extends AbstractTransformation {
^
getcontent.java:19: cannot resolve symbol
symbol : class StreamTransformationException
location: class GetContent
throws StreamTransformationException {
^
getcontent.java:47: cannot resolve symbol
symbol : class TransformationInput
location: class GetContent
public void transform(TransformationInput arg0, TransformationOutput ar
g1) throws StreamTransformationException {
^
getcontent.java:47: cannot resolve symbol
symbol : class TransformationOutput
location: class GetContent
public void transform(TransformationInput arg0, TransformationOutput ar
g1) throws StreamTransformationException {
^
getcontent.java:47: cannot resolve symbol
symbol : class StreamTransformationException
location: class GetContent
public void transform(TransformationInput arg0, TransformationOutput ar
g1) throws StreamTransformationException {
^
getcontent.java:48: cannot resolve symbol
symbol : method getTrace ()
location: class GetContent
getTrace().addInfo("JAVA Mapping Called");
^
11 errors
Can you tell me, why you want to remove the encoding attribute? Does this lead to error in receiver side?
encoding attribute is XMLstandard and if receiver cannot interpret it, it should e fixed at receiver side.
What puzzles me also is this namespace:
> - <JEBIZ_HEADER xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
As this namespace is not used in the XML, it can be omitted. It does not make sense to declare a namespace which is not used.
If you do mapping just from an example XML, you should figure out if you can work with other payloads also when it is semantically identic.
In my opinion you do a lot of work which you do not need.
Hi,
Removing encoding and using the namespace as "http://www.w3.org/2001/XMLSchema-instance" is the clients requirement.
i am doing this mapping not for an example, but it is the requirement of the project.
the actual requirement of the o/p xml is as below. To meet the below requirement i m tried to modify:
<?xml version="1.0" ?>
- <JEBIZ_HEADER xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <HEADER>
<MINISTRY_CODE>TOT</MINISTRY_CODE>
<DEPARTMENT_CODE>000</DEPARTMENT_CODE>
<ENTITY_CODE>TOT~000</ENTITY_CODE>
<STATUS>NEW</STATUS>
</HEADER>
- <DETAILS>
- <SEGMENT>
<NUMBER>01</NUMBER>
<LABEL>Account Assignment Cat</LABEL>
</SEGMENT>
</DETAILS>
</JEBIZ_HEADER>
Hi,
Can you let me know how can i remove ns1 in the following:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:JEBIZ_HEADER xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">
<HEADER>
<MINI_CODE>TOT</MINISTRY_CODE>
<DEP_CODE>000</DEPARTMENT_CODE>
<ENTITY_CODE>TOT</ENTITY_CODE>
<STATUS>NEW</STATUS>
</HEADER>
<DETAILS>
<SEGMENT>
<NUMBER>01</NUMBER>
<LABEL>Account Assignment Cat</LABEL>
</SEGMENT>
</ns1:JEBIZ_HEADER>
Hi jjma1706,
You are in PI 7.1 - right?
Try:
public class Test_Neu extends AbstractTransformation {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// Add your code here
String inData = convertStreamToString(in);
String outData = inData.replaceAll("ns1:","");
try {
// The JAVA mapping output payload is returned using the
// TransformationOutput class
// arg1.getOutputPayload().getOutputStream()
out.write(outData.getBytes());
} catch (Exception exception1) {
}
}
//to test the mapping as a standalone code - main method! delete for PI!
public static void main(String[] args) {
try {
InputStream in = new FileInputStream(new File("D:/PETER/in.xml"));
OutputStream out = new FileOutputStream(new File("D:/PETER/out.xml"));
Test_Neu myMapping = new Test_Neu(); myMapping.execute(in, out); }
catch (Exception e) { e.printStackTrace();
}
}
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
getTrace().addInfo("JAVA Mapping Called");
this.execute(arg0.getInputPayload().getInputStream(), arg1
.getOutputPayload().getOutputStream());
}
public String convertStreamToString(InputStream in) {
StringBuffer sb = new StringBuffer();
try {
InputStreamReader isr = new InputStreamReader(in);
Reader reader = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
sb.append((char) ch);
}
reader.close();
} catch (Exception exception) {
}
return sb.toString();
}
}
This line
String outData = inData.replaceAll("ns1:","");
is doing the work for you!
Test it locally! Look at
//to test the mapping as a standalone code - main method! delete for PI!
public static void main(String[] args) {
try {
InputStream in = new FileInputStream(new File("D:/PETER/in.xml"));
OutputStream out = new FileOutputStream(new File("D:/PETER/out.xml"));
Test_Neu myMapping = new Test_Neu(); myMapping.execute(in, out); }
catch (Exception e) { e.printStackTrace();
}
}
That uses local input and output filenames. Before you make the JAR for your PI system - delete this part or make a comment out of it!
Hope it helps - best regards,
Peter
> This line
>
String outData = inData.replaceAll("ns1:","");
> is doing the work for you!
I am sorry, this will not help. The namespace declaration must have prefix xsi.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
If you just remove all prefixes the XML will be semantically different and therefore wrong
Hello Stefan,
You are right!
I adapted the code a little:
String inData = convertStreamToString(in);
String outdata1 = inData.replaceAll("ns1:", "");
String outdata2 = outdata1.replaceAll("xmlns:ns1=\"http://www.w3.org/2001/XMLSchema-instance\"", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
try {
// The JAVA mapping output payload is returned using the
// TransformationOutput class
// arg1.getOutputPayload().getOutputStream()
out.write(outdata2.getBytes());
} catch (Exception exception1) {
}
which gives me this output:
<?xml version="1.0" encoding="UTF-8"?>
<JEBIZ_HEADER xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HEADER>
<MINI_CODE>TOT</MINISTRY_CODE>
<DEP_CODE>000</DEPARTMENT_CODE>
<ENTITY_CODE>TOT</ENTITY_CODE>
<STATUS>NEW</STATUS>
</HEADER>
<DETAILS>
<SEGMENT>
<NUMBER>01</NUMBER>
<LABEL>Account Assignment Cat</LABEL>
</SEGMENT>
</JEBIZ_HEADER>
It looks okay to me now, ns1: are gone and :xsi prefix is there!
Best regards,
Peter
Hi,
Is there any possiblities that we can change the ns1 to xsi and remove ns1 at the beginning of the tag using Graphical mapping
Existing o/p:
- <ns1:JEBIZ_HEADER xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance">
Expected o/p:
- <JEBIZ_HEADER xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Hi Stefan,
I am trying XSLT mapping for this scenario and using ALTOVA mapforce tool for it.
I have downloaded the trail version of ALTOVA. I have created the source and target XSD and mapped it . the mapping validation is successful with 0 error and 0 warnings.
But when i click at XSLT or Output tab ALTOVA Mapforce encounters a problem and needs to close.
Is it b'cos of the trail version or something wrong in the mapping?
Hi ,
I am trying XSLT mapping for this scenario and using ALTOVA mapforce tool for it.
I have downloaded the trail version of ALTOVA. I have created the source and target XSD and mapped it . the mapping validation is successful with 0 error and 0 warnings.
But when i click at XSLT or Output tab ALTOVA Mapforce encounters a problem and needs to close.
Is it b'cos of the trail version or something wrong in the mapping?
Hi jjma1706,
I have the complete java mapping and it works for your xml-structure. I can create the JAR file for you so you can just import that into the PI. Should I email it to you? Then please post your email address here.
Or should I post my java code again and you create the JAR file yourself?
Best regards,
Peter
Hello Jaya,
The JAR file you just import into your PI 7.1. Do you know how to do that?
Go to Integration Repository, Mapping Object -> Imported Archives. You must create a new Imported Archive and import the file.
In your Operation Mapping under "Mapping" you can choose your Archive then and also test it with the "Test" tab.
If you want to look at the code I posted earlier yourself you need to import the library "com.sap.xpi.ib.mapping.lib".
Also be careful with your JDK-version: I am using 1.4. If you use the latest one (1.6) you will probably get an error in PI 7.1.
Best regards,
Peter
Hi,
I don't understand that.
After importing a JAR file this is what the archive should look like:
http://public.fotki.com/pezibaer420/pi/archive.html
This is an example for an operation mapping:
http://public.fotki.com/pezibaer420/pi/operation.html
I have 2 mappings in there, first a graphical one and then the java one.
Maybe you imported another file and not the JAR file I sent you!?
Best regards,
Peter
Hi Peter,
Thanks for the reply. I had moved the .JAR file to zip file and added this ZIP file to the Imported archives.
Now i have modified the IA and included the JAR file again. IT WORKED... Thanks.
And we have a field END_DATE, which should occur as <END_DATE xsi:nil="true" />
but we are getting in the output file as below:
<END_DATE>0000-00-00</END_DATE>
Can you let me know how to change this? I tried to pass it through message mapping but resulted in wrong value.
So you have
<END_DATE>0000-00-00</END_DATE>
in your source XML. Is the value always 0000-00-00?
And it should look like this in your target file?
<END_DATE xsi:nil="true" />
I will have to adapt the Java mapping and will resend the JAR file to your email.
You can not change JAR files!
Best regards,
Peter
Hi,
By using the below code received from Peter, we are were able to remove the prefix, encoding and change the END_DATE format.
Please find the code below:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
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 DeletePrefixesEnddateAndEncoding extends AbstractTransformation {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// Add your code here
String inData = convertStreamToString(in);
String outdata = inData.replaceAll("ns1:", "");
String outdata2 = outdata.replaceAll("xmlns:ns1=\"http://www.w3.org/2001/XMLSchema-instance\"", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
String outdata3 = outdata2.replaceAll(" encoding=\"UTF-8\"?", "");
String outdata4 = outdata3.replaceAll(" encoding=\"utf-8\"?", "");
String outdata5 = outdata4.replaceAll("<END_DATE>0000-00-00</END_DATE>", "<END_DATE xsi:nil=\"true\" />");
try {
// The JAVA mapping output payload is returned using the
// TransformationOutput class
// arg1.getOutputPayload().getOutputStream()
out.write(outdata5.getBytes("ISO-8859-1"));
} catch (Exception exception1) {
}
}
// Un comment to test the mapping as a standalone code
/* public static void main(String[] args) {
* try {
* InputStream in = new FileInputStream(new File("D:/PETER/in.xml"));
* OutputStream out = new FileOutputStream(new File("D:/PETER/out.xml"));
* DeletePrefixesEnddateAndEncoding myMapping = new DeletePrefixesEnddateAndEncoding(); myMapping.execute(in, out); }
* catch (Exception e) { e.printStackTrace();
* }
}*/
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
getTrace().addInfo("JAVA Mapping Called");
this.execute(arg0.getInputPayload().getInputStream(), arg1
.getOutputPayload().getOutputStream());
}
public String convertStreamToString(InputStream in) {
StringBuffer sb = new StringBuffer();
try {
InputStreamReader isr = new InputStreamReader(in);
Reader reader = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
sb.append((char) ch);
}
reader.close();
} catch (Exception exception) {
}
return sb.toString();
}
}
Try after replacing the desired namespace in inbound Message Type under "XML Namespace".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
If you want to remove name space one simple way is remove name space in target message type under data type column.
if you want to add W3.ORG use SXLT Mapping or JAVA Mapping(regulare expresion will work.
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
i tried to remove remove the Namespace in the target message type.
but it showed me the following error and there is no values in the structure tab. its empty
Object Message Type: MT_LEBIZ_ACH_RCV | http://lebiz.ach.com references the inactive object Data Type: DT_LEBIZ_ACH_RCV
> Object Message Type: MT_LEBIZ_ACH_RCV | http://lebiz.ach.com references the inactive object Data Type: DT_LEBIZ_ACH_RCV
Did you activate the data type ?
Regards,
Sunil Chandra
User | Count |
---|---|
76 | |
10 | |
9 | |
8 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.