cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Logic: XML Node output

neilpadilla
Participant
0 Kudos
57

Hi Guys,

Could you please help me on a mapping logic that I need.

I have the following source xml format. The source and target message are the same.

<MessageType>
<Node>
  <ItemCount>1000</ItemCount>
  <BASE>ABC</BASE>
</Node>
<Node>
  <ItemCount>1001</ItemCount>
  <AMOUNT>ABC</AMOUNT>
</Node>
<Node>
  <ItemCount>1002</ItemCount>
  <RATE>ABC<RATE>
</Node>
</MessageType>


If RATE Exists then, it will output all Nodes.
Else, if it does not exist, it will only output first occurrence of the node.

Thanks and Regards,

Neil

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Neil,

Try the below UDF.

Execution Type: All Values Of Context


public void mapNode(String[] rate, ResultList result, Container container) throws StreamTransformationException {

  boolean found = false;

  for (String str : rate) {

  if (str.equals("true"))

  found = true;

  result.addValue("");

  }

  if (!found) {

  result.clear();

  result.addValue("");

  }

  }

Use below mapping.

Regards,

Praveen.

neilpadilla
Participant
0 Kudos

Hi Praveen,


Thanks a lot. This UDF and mapping works.

I was able to produce only the first Node if the RATE does not exists.

Regards,

Neil

iaki_vila
Active Contributor
0 Kudos

Hi Neil,

If Praveen has solved your issue you should to close the thread according this

Please, try to follow a good behavior in the forum: http://scn.sap.com/docs/DOC-18590

Regards.

Answers (1)

Answers (1)

Ryan-Crosby
Active Contributor
0 Kudos

Hi Neil,

A mapping like the following for the Node level should achieve what you need based on what you have described:

If a node does not exist for RATE (assuming blanks are not allowed) then only the first node value that you noted above with BASE would be passed to the target.

Regards,

Ryan Crosby

neilpadilla
Participant
0 Kudos

Hi Ryan,


Thanks for your suggestion. I was able to produce all the nodes if my source message has RATE.

Although, if the RATE does not exists, it also produces all the nodes. Not the first occurrence only.


Regards,

Neil

Ryan-Crosby
Active Contributor
0 Kudos

Hi Neil,

It does work as I confirmed it but you have to adjust the sort to be descending instead of the default ascending so the empty string does not end up as the entry remaining after the CollaspeContext call.

Regards,

Ryan Crosby