cancel
Showing results for 
Search instead for 
Did you mean: 

Create target XML nodes based on field names in the source

pi_consultant1
Participant
0 Kudos

Hi experts,

I have a Requirement where in I need to map the field names from Source structure to the target structure...

For Example:

My Source structure:

<field1>123</field1>

<field2>XYZ</field2>

Expected Target structure:

<Node>

<Fieldname>field1</Fieldname>

<Fieldvalue>123</Fieldvalue>

</Node>

<Node>

<Fieldname>field2</Fieldname>

<Fieldvalue>XYZ</Fieldvalue>

</Node>

Can you please advise how to achieve this in Graphical Mapping of SAP PI (and maybe with an UDF)?

Best regards,

John

View Entire Topic
fprokopiuk
Active Participant
0 Kudos

Hello John,

For UDF + graphical mapping alternative you can refer to this blog: https://blogs.sap.com/2012/11/05/message-mapping-play-around-with-target-structure/.

However I would go with XSLT option here which Ryan suggested.

pi_consultant1
Participant
0 Kudos

Thank you Filip.

This is a useful blog, however my usecase is exactly the other way around. So the source looks like this:

<Items>

<CompanyA>abc corp</CompanyA>

<CompanyB>xyz info</CompanyB>

</Items>

And the target like this:

<Rows>

<Key>CompanyA</Key>

<Value>abc corp</Value>

</Rows>

<Rows>

<Key>CompanyB</Key>

<Value>xyz info</Value>

</Rows>

It would be great to know exactly what to do if its the other way around...

I also will look at the XSLT option.

Regards,

John

fprokopiuk
Active Participant

To get it other way around you need to find method that reads structure of the input. You can check this documentation: https://help.sap.com/doc/javadocs_nw75_sps04/7.5.4/en-US/PI/overview-summary.html for existing packages. You should find something in com.sap.aii.mappingtool.tf7.rt and com.sap.aii.mapping.api packages.

fprokopiuk
Active Participant

As an alternative you can use "Return as XML" option and parse it in udf using javax.xml.parser. Example of reading xml node names: https://stackoverflow.com/questions/10784036/retrieving-xml-node-names.