on 10-20-2011 9:52 AM
Hi gurus,
we have following requirement to solve;
on receiver side we have a segment without namespace. It is possible to add namespace at the graphical mapping?
<root>
<id>1111</id>
<name>max mustermann</name>
<unit>B1</unit>
</root>
expected structure
<root xmlns="http://www.org/xml/v0300">
<id>1111</id>
<name>max mustermann</name>
<unit>B1</unit>
</root>
solution for this problem will be much appreciated,
Kind Regards
PM
You can achieve this with a java or abap mapping.
In abap:
xxx->set_attribute( name = 'xmlns' value = "http://www.org/xml/v0300").
Regards,
Carme
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
It'll be something like...
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<ns0:MT_Ex xmlns:ns0="yournamespace">
<xsl:copy-of select="." />
</ns0:MT_Ex>
</xsl:template>
</xsl:stylesheet>
Refer this
Regards,
Priyanka
Hi Peter,
You can use the following java mapping to meet your requirement
for PI 7.1 and above (if you are working with lower versions please let us know, since java mapping code will be different for lower versions)
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 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 copyNode extends AbstractTransformation {
/**
* @param args
*/
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// TODO Auto-generated method stub
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 rootin;
Node rootout;
Element r;
rootin=docIn.getDocumentElement();
rootout=docOut.importNode(rootin, true);
docOut.appendChild(rootout);
r=(Element)docOut.getElementsByTagName("root").item(0);
r.setAttribute("xmlns", "\"http://www.org/xml/v0300\"");
transform.transform(new DOMSource(docOut), new StreamResult(out));
}
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{
copyNode genFormat=new copyNode();
FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\namespaceAdd.xml");
FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\namespaceAdd1.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
One more thing, you have not mentioned the scenario. If the scenario has a file adapter in sender side, and you are using File content conversion, then please put the namespace value in content conversion parameters -> Document namespace. Then you will receive the namespace value in source message.
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also check these links:
http://stackoverflow.com/questions/2686650/xslt-add-namespace-to-root-element
http://www.google.ru/#hl=ru&source=hp&q=xsltaddnamespacetorootelement&oq=xsltadd+name&aq=2&aqi=g2&aql=1&gs_sm=e&gs_upl=692l5644l0l7158l13l11l0l4l4l0l208l598l0.1.2l3l0&fp=1&biw=1366&bih=677&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&cad=b
BR,
Chizz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
You can achieve this with java mapping....
Also refer
http://wiki.sdn.sap.com/wiki/display/XI/ChangingNamespacesandtheencodingformatof+XML
Regards,
Priyanka
Edited by: priyanka.anagani on Oct 20, 2011 11:03 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.