cancel
Showing results for 
Search instead for 
Did you mean: 

Pass namespace at root level node and truncate ns1 tags

Former Member
0 Kudos

Hi Guys,

I have a question on how to do it and any sample code/help will be appreciated.

I have seen a couple of threads related to this but doesnt seem to quite link up with my scenario :

I am using a xsd given by 3rd party but they also want the target payload xml to look like this :

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

<ABC xmlns="http://www.test1.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema">

.

.

.

.</ABC>

My PI maiing is producing the xml as following :

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

<ns1:ABC  xmlns="http://www.test1.com">

.

.

.

</ns1:ABC>

Any suggestion and help on how to acheive the 3rd party xml payload i.e. stripp of ns1 tags and insert xmlns:xsi="http://www.w3.org/2001/XMLSchema namepspace at root level along with the target namespace.

thanks in advacne.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Did this by deploying JAVA mapping after Message mapping.

Answers (1)

Answers (1)

Harish
Active Contributor
0 Kudos

Hi,

you can use one to one message mapping. and use the below code in Init function of message mapping.

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", "");

  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,

Can you please relate the above code to my scenario ?

Harish
Active Contributor
0 Kudos

Hi,

The above code is only to remove ns1 tages from the target XML. to add the namespace you need to add the code.

regards,

Harish