cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in adding namespace at adapter level

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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?

anupam_ghosh2
Active Contributor
0 Kudos

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

stefan_grube
Active Contributor
0 Kudos

I thought you received an xsd from legacy team. Have you created your message type based on externed xsd? Or did you create similar structure as ESR data type?

Former Member
0 Kudos

Created structure (DT) on own; not by xsd

stefan_grube
Active Contributor
0 Kudos

You could remove XML namespace in message type and as well in AnonymizerBean. However the best option would be importing external xsd and create message type based on it.

former_member182004
Contributor
0 Kudos

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.

former_member182412
Active Contributor
0 Kudos

Hi Naresh,

Set Qualify Schema for elements in your data type then your input xml expects all elements with prefix and you can add the namespace using XMLAnonymizerBean module.

Regards,

Praveen.

Former Member
0 Kudos

sorry it is coming as

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

<ns1:WorkAuthorization