cancel
Showing results for 
Search instead for 
Did you mean: 

DeepXML to flat file conversion.

Former Member
0 Kudos

I am trying to convert a deep XML file to flat file using UDF.

Nodes with format <Tag>Value</Tag> are getting generated in the flat file.But the empty Tags <TAG/> is not generating any node in output file.

The scenario is :

2 mappings have been used.

1. Message Mapping which is an IDOC to file scenario.Mapping is such that,Node function " Map with Default" has been used to generate a blank space wherever there is no value at the source side.This works fine .

2. Again a second mapping has been used which converts the deep XML to  a single node XML which has all the elements.

with the use of UDF.But here ,empty tags are not getting generated.

Any other approach in UDF to achieve the same ?

Below is the UDF code used.

public void DeepXMLtoFlat(String[] in, ResultList eachLine, ResultList element, Container container) throws Stream

java.util.regex.Matcher m = java.util.regex.Pattern.compile ("<(.*?)>[^<]*</\\1>") .matcher(in[0]);
  int count = 0; 
  eachLine.addValue(""); 
  String elem; 
  while (m.find()) { //Loop over elements. 
  elem = m.group(); 
  if (elem.startsWith("<Tag>") && count > 0) { //From second Tag 
  eachLine.addValue(""); 
  element.addContextChange(); 
  } 
  //Get text content of element. E.g: <Name>AAA</Name> = AAA. 
  element.addValue(elem.substring(elem.indexOf(">") + 1, elem.indexOf("</"))); 
  count++; 

  } 


Source structure :



Target structure :


Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos
former_member182412
Active Contributor
0 Kudos

Hi Aakanksha,

You can use this blog to place the entire XML into single field Convert the Input xml to String in PI 7.1 using Standard Graphical Mapping

Name field should be return as XML.

Result:

Regards,

Praveen.

Former Member
0 Kudos

Hi Praveen ,

We don't want everything in one string. Requirement is to convert the deep nested XML structure into simple single level XML structure so that fcc can be applied. At the end,tab delimited file is required.

former_member182412
Active Contributor
0 Kudos

Hi Aakanksha,

Can you give me the sample deep XML and required tab delimited file? I will provide you better approach.

Regards,

Praveen.

Former Member
0 Kudos

Hi Praveen..

PFA nested XML..

Target file would be just tab delimited with spaces for empty nodes.

Harish
Active Contributor
0 Kudos

Hi Aakanksha,

You are using the mapwithdefault in first mapping, so is mapwithdefault configure with spaces? if not then your UDF will skip the empty tag as per code logic.

regards,

Harish

Former Member
0 Kudos

Hi Harish ,

Yes map with default is already configured with spaces.