on 12-30-2015 10:34 AM
Hello All,
We working on a File to IDOC scenario where PI needs to pick XML file from file folder. Source structure was created using XSD given by Legacy team.
While testing the interface, it is failing at adapter level due to a namespace that is being part of header in the file.
XML tags present in customer given input file is as follows:
<?xml version="1.0" encoding="UTF8" standalone="yes"?>
<WorkAuthorization xmlns="http://workserv.com/SalesI001/WorkAuthorization/AUG2005">
Message type xml tags are as below:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:WorkAuthorization xmlns:ns1="urn:col.ce:Sales:PP">
Hence we tried using in module of the channel:
Parameter name : anonymizer.acceptNamespaces
Parameter value : urn:col.ce:Sales:PP" ns1
But the converted xml is
<?xml version="1.0" encoding="UTF-8"?>
<ns1:PaymentAuthorization>
which is not taking the namespace ( urn:col.ce:Sales:PP) that is required by message type
Can some one help on this
Regards,
Moorthy
Go to ESR, change XML names space in message type to http://workserv.com/SalesI001/WorkAuthorization/AUG2005 The XML namespace and the object namespace need not be the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Stefan,
Thanks for your reply.
But unfortunately it is not well formed xml it seems as it is failing in mapping. It is due to missing prefix tag "ns1" inside the xml. When I tried to add this thru in parameter value as
http://workserv.com/Sales1001/WorkAuthorization/AUG2005 ns1
It is getting added to all fields in the structure. How can I avoid this?
Hi Naresh,
You can add a small java mapping code to correct the root tag name and the namespace in the same OM which has the MM. The MM execution will follow the java mapping execution.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
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 RemoveNamespace extends AbstractTransformation{
/**
* @param args
* @throws FileNotFoundException
* @throws StreamTransformationException
*/
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
execute(arg0.getInputPayload().getInputStream(),arg1.getOutputPayload().getOutputStream());
}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException
{
try
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(in);
Document docOut = docBuilder.newDocument();
Node SourceRootNode=doc.getDocumentElement();
Node targetRootNode=docOut.importNode(SourceRootNode,true);
if(((Element) targetRootNode).hasAttribute("xmlns"))
{
((Element) targetRootNode).removeAttribute("xmlns");
}
docOut.appendChild(targetRootNode);
docOut.renameNode(targetRootNode, "urn:col.ce:Sales:PP","ns1:"+SourceRootNode.getNodeName());
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(docOut);
StreamResult result = new StreamResult(out);
// Output to console for testing
// StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
}
catch(Exception e)
{
e.printStackTrace();
throw new StreamTransformationException(e.getMessage());
}
}
}
Regards
Anupam
Hi Naresh, as Stefan suggested the best option is creating the DT based on the XSD files received.
This guide may help you to import them (if they're nested)
Importing XSD’s Schema With External References (step-by-step guide)
http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/07/18/importing-xsd-s-schema-with-exter...
Regards,
Juan.
sorry it is coming as
<?xml version="1.0" encoding="UTF-8"?>
<ns1:WorkAuthorization
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
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.