cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping help

former_member190996
Participant
0 Kudos

Hi,

I am trying to implement the JMS -> SOAP interface on PI 7.11. The inbound interface is expecting the CDATA[] in xml format and it's being validated against their XSD. If the validation fails, like if the data format or attributes in the CDATA xml does not match to the one in XSD, the message fails. The sender is sending the data with different structure and with different attributes. Now, my question is how can I map the outbound data with different hierarchies, different attribute names from the inbound and convert it to a CDATA? Please let me know.

Best Regards,

Sai

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Sai,

  • Do the message mapping between source structure to target structure which is in CDATA section of the xml

  • Do another message mapping after the first message mapping and pass the root node to CDATA field in the actual target message and select return as xml for root node of the source message.

Regards,

Praveen.

former_member190996
Participant
0 Kudos

Hi Praveen,

This means should I have to create two message mappings and use them in OM one after the other? Is this the best approach? Since there are 100s of fields, don't you think it would have any impact on the performance? Please help me understand.

Thanks,

Sai

former_member182412
Active Contributor
0 Kudos

Hi Sai,

Only the first mapping you do the actual mapping field to field, second mapping is just wrapping the entire XML into one field so there will be no performance impact.

Regards,

Praveen.

former_member190996
Participant
0 Kudos

Hi Praveen,

Thank you for the clarification. I have done exactly as suggested, but the replaceString doesn't want to replace anything. I have tested with different values. Please let me know what am I missing?

This is how the mapping looks like:

Regards,

Sai

former_member182412
Active Contributor
0 Kudos

Hi Sai,

Take the xml string from test message tab of message mapping(by click on generate instance then it will create empty xml) and use it in replace string.

Regards,

Praveen.

former_member182412
Active Contributor
0 Kudos

If the above does not work use below UDF.

Mapping:

former_member190996
Participant
0 Kudos

Hi Praveen,

This is exactly, what I have done. And also, the result is having all the <, " and > instead of the actual special characters. Please check below:

former_member182412
Active Contributor
0 Kudos

Hi Sai,

  • Those &lt; escape character for '<' and &gt; is for '>'
  • If you put the whole xml into one field it will be like that.
  • But you need to remove the xml declaration from the string that is why i have given the UDF to remove xml declaration from the string.

Regards,

Praveen.

former_member190996
Participant
0 Kudos

I have done the same thing Praveen, nothing changes. The strange thing is, I have tried to testing this in the normal java class on NWDS, I can't replace there as well. The below is the code that I have used:


public static void main(String[] args) {

        String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

        System.out.print(input+"\n");

        input.replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","Test");

        System.out.print(input);

}

This always print the <?xml version=\"1.0\" encoding=\"UTF-8\"?> as output. Is there a way that I could debug it?


Regards.

former_member182412
Active Contributor
0 Kudos

Hi Sai,

Try below code.


public static void main(String[] args) {

  String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

  System.out.print(input + "\n");

  input = input.replaceAll("\\<\\?xml(.+?)\\?\\>", "Test").trim();

  System.out.print(input);

  }

Regards,

Praveen.

former_member190996
Participant
0 Kudos

Hi Praveen,

This works in the java class on the NWDS, but not at the UDF. Do you think I should use the java mapping? or is there any other way to achieve using the UDF?

former_member182412
Active Contributor
0 Kudos

Hi Sai,

This will work with UDF also did you try the UDF which i provided above. I have tested and it is working.


public String removeXMLDec(String input, Container container) throws StreamTransformationException {

  return input.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();

  }

Regards,

Praveen.

former_member190996
Participant
0 Kudos

It did work Praveen, thanks a lot

One last thing; can you tell me how could I replace the &lt;, &quot;, &gt; within the UDF please.

former_member182412
Active Contributor
0 Kudos

Hi Sai,

You no need to replace them those are the escape characters and it is just display, if you click pretty print button in the message mapping test tab then you will be able to see the CDATA section.

This will work for this requirement because i also done the same thing in my project it works perfectly.

Do close the call as per this

Regards,

Praveen.

former_member190996
Participant
0 Kudos

Thanks a lot Praveen, appreciate your help.

Answers (1)

Answers (1)

apu_das2
Active Contributor
0 Kudos

Hi Sai,

As per my knowledge, there is two options -

1. take whole source structure into a single parameter and write an UDF - where you can read attribute wise as per your requirement and then send data to target end.

2. Go for Java mapping.

Thanks,

Apu

former_member190996
Participant
0 Kudos

Hi Apu,

I can leverage UDF or java maaping. Could you please let me know how can I overcome the differences in the source and target message structures and different attribute names?