on 09-26-2016 12:18 PM
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 :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.