cancel
Showing results for 
Search instead for 
Did you mean: 

Using multiple XSDs in Message Mapping

Former Member
0 Kudos

Hello,

We have a Japanese customer that uses a business standard XML file for their invoices. I've received a number of XSD files that are linked using include statements within the XSDs. 

In SAP PI 7.1 I am trying to import the schema xsds as a set of external definitions to then use in a message map to produce an XML document like the example attached (AEONInvoiceSample.xml). I am able to import the XSDs using the “import external definitions” function but a lot of the attributes are missing from the message definitions, and I cannot use them within a message map to produce 1 output - when I come to use them in a message map I can only use external definitions with elements defined so I end up with three different outputs rather than one (I was hoping to be able to use the SGE_InvoiceProxy1.xsd to link them all together (renamed to XML so I could attach to this discussion) but I can’t use this for the output message in the mapping – I guess that’s because there aren’t any elements defined in it). Should I be using an Integration Process to then combine the three messages together or is there a way I can do this without having to use one? I am also finding that by having the 3 different outputs I now don’t have the xmlns information at the top of the XML output.

I can try and create my own version of the xsd but because this is a business standard XML I would rather use the XSDs provided

Any help greatly appreciated!

Many thanks,

Ollie

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Oliver,

You can use the xsds provided in your service interface and then use a blank xml in your message mapping see attachment for sample blank xml.

In the example above, I used the blank xml for my source and target, and then mapped them 1..1. See output from message mapping test:

The namespace sh get translated to ns0 and so on (standard PI behavior). You can just use a simple find replace (via XSLT mapping or Java Mapping as the last mapping in the operation mapping) to revert it to the correct namespaces.

The drawback from importing a blank XML is that the cardinalities do get lost, so you have to map each field.

Hope this helps,

Mark

Former Member
0 Kudos

Hi Mark,

This is great, thank you! However I'm inexperienced with XSLT and am struggling to get the namespace prefixes to look as I want them to. Can you suggest anything for me to try?

Thanks again,

Ollie

gagandeep_batra
Active Contributor
0 Kudos

Hi Oliver

for namespace you can look for following thread:

Regards

GB

Former Member
0 Kudos

Hi Gagandeep,

Thanks for the feedback.

The XSLT mentioned in the link provided seems to be defining each element within each namespace. I was hoping that there would be something quicker and easier to save on coding. I've tried using namespace-alias but that doesn't seem to be doing anything. I've also tried the following for my ns0, ns1, ns2 and ns3 namespaces:

<xsl:template match="@ns0:*">

  <xsl:element name="sh:{local-name()}"> 

   <xsl:apply-templates select="@* | node()"/>

  </xsl:element>

</xsl:template>

This is removing the tags around the elements altogether.

Sorry if I'm missing something obvious. Do you know of anything else I can try? Mark mentioned a "simple find replace" XSLT and although I can replace values within elements I seem to be unable to change the namespaces.

Many thanks,

Ollie

Harish
Active Contributor
0 Kudos

Hi Oliver,

If you only want to change the XML prefix, you can achieve this with simple java code in graphical map (addition graphical map) with below code is in Attributes and Methods section

public void transform(TransformationInput in, TransformationOutput out)
throws StreamTransformationException {
try {

  String sourcexml = ""; String targetxml =""; String line ="";
  InputStream ins =    in.getInputPayload().getInputStream();
  BufferedReader br = new BufferedReader( new InputStreamReader(ins));
  while ((line = br.readLine()) != null)   
   sourcexml +=line;//+"\n";  
  br.close();

  targetxml =sourcexml;
  targetxml = targetxml.replaceAll("ns0", "pfx");
  out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

} catch (Exception e) {   throw new StreamTransformationException(e.getMessage());   }
}

public String concate(String str1, String str2, Container container) throws StreamTransformationException{
  //String output = null;
  return (str1+str2);
}

regards,

Harish

Former Member
0 Kudos

Hi Harish,

Sorry for the slow reply. The info provided was really helpful and the java does exactly what I wanted.

Many thanks,

Ollie

Harish
Active Contributor
0 Kudos

Hi Oliver,

Good to hear that your issue is resolved. If you do not have any more question, please close the discussion.

regards,

Harish

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Oliver,

You need to create references between the multiple external definitions you created for multiple xsds.

Please use following link on SAP Help which explains how to achieve the same:

External Definitions (SAP Library - Enterprise Services Repository for SAP NetWeaver CE)

You will need to use the Source field which by default is blank in External Definition to achieve the same.

Hope this helps!!!

Regards,

Anurag