|
Rank: Newbie
Joined: 4/17/2014 Posts: 3 Location: Italy
|
Hi all, I have to map a text file which have the following master-details structure:
Code:HEADER---- DET01.... DATA... ADDR address1 .... DET02 DATA... DET03 DATA... ADDR address2.... DET04 DATA... DET05 DATA...
DET signals the start of a new detail DATA is some info about this entity ADDR contains the address of this entity, since more details might share the same address, the ADDR row is to be added just when it is different from the previous detail structure. So in the above example the details 01,02 share the same address, and details 03,04,05 share the other address.
I need to map this information into a hierarchical XML structure, in which the addresses are separated from the details, and a reference list to the details is mantained:
Code:<HEADER> .... <ADDRESSES> <ADDRESS> <VALUE>address1</VAUE> <REFERENCES> <REF>01</REF> <REF>02</REF> </REFERENCES> <ADDRESS> <ADDRESS> <VALUE>address2</VAUE> <REFERENCES> <REF>03</REF> <REF>04</REF> <REF>05</REF> </REFERENCES> <ADDRESS> </ADDRESSES> <DETAILS> <DETAIL> <NUM>01</NUM> <DATA>.....</DATA> </DETAIL> <DETAIL> <NUM>02</NUM> <DATA>.....</DATA> </DETAIL> ..... <DETAIL> <NUM>05</NUM> <DATA>.....</DATA> </DETAIL> </DETAILS> </HEADER>
I have no issues in creating the <Header> and <Details> structure, but I am fighting hard for achieving the Addresses part. Do some of you encountered a similar situation or can give me some clue?
Thank you.
|
|
Rank: Advanced Member
Joined: 8/19/2012 Posts: 149 Location: Ireland
|
Not sure about you, but I always find such descriptions very complicated. Attaching a mapping would be much more illustrative...
If you only need to populate an address if it is different, I suggest creating a structure which is based on grouping by address field.
|
|
Rank: Advanced Member
Joined: 12/13/2005 Posts: 2,856 Location: Mauritius
|
You need to use MapForce FlexText to parse your text file, then everything should be fine.
|
|
Rank: Newbie
Joined: 10/28/2002 Posts: 1,283 Location: AT
|
Attached is a sample mapping which shows you how to do this.
Things to note:
a) A FlexText template was used to parse the source.
b) a number of intermediate components were needed to get the data into a more manageable structure. You can replace the intermediate xml schema structures with variables instead. I did not use variables in this example so that you can see the intermediate output at each step of the way in order to better understand how the mapping works. The advantage of using variables is the fact that you will not generate any intermediate output files, only the final target output.
c) i used "group-starting-with" to group the data according to the address.
d) there may be other ways to simplify / optimize this mapping. It is just an example to show you that it can be done.File Attachment(s): test.zip (4kb) downloaded 221 time(s).
|
|
Rank: Newbie
Joined: 4/17/2014 Posts: 3 Location: Italy
|
Thank you island for your reply, I tried studying what you did, but I had the following issues:
the mfd seems to be out of synch with the FlexText template so I couldn't actually run it. In the FlexText, after you split the header, you do a repeat split using the ADDR separator, but this gives you the following three blocks:
Code:ADDR address1 DET02 DATA DET03 DATA
Code:ADDR address2 DET04 DATA DET05 DATA
Which seems to separate the DET01 row from its address (and also the DET03) but maybe I didn't understand fully the mapping you do in the mfd.
I tried using a variable to hold an Address node, but I would need a mechanism that would allow me to "reuse" a previously matched node when one isn't provided in the current element.
I think the key information here is the group-starting-with: if I understand correctly I should be able to first group all my details using the address element (if given), those element without it will be grouped together with the previous one, am I right? This should give me an intermediate structure from which to get to my final one.
Thank you very much for your insight, it helped me a lot.
|
|
Rank: Newbie
Joined: 10/28/2002 Posts: 1,283 Location: AT
|
Hi,
sorry, yes it seems that I uploaded the wrong version of the flextext template and mapping. I have now reuploaded the files.. please redownload all example files and then open the mapping again, it should now work. Please note that when clicking on the output tab "testout.xml" is the final output in the mapping.
If anything is unclear please let me know.
|
|
Rank: Newbie
Joined: 4/17/2014 Posts: 3 Location: Italy
|
Wonderful, thanks to your help I was able to get to my results, the only difference with your mapping is that I used an "exists" as the input for the group-starting-with. I still wonder thought if it were possible to skip the first intermediate schema, that is, applying the grouping directly to the output of the FlexText component.
Thank a lot for your help.
|
|
Rank: Newbie
Joined: 10/28/2002 Posts: 1,283 Location: AT
|
Quote:I still wonder thought if it were possible to skip the first intermediate schema, that is, applying the grouping directly to the output of the FlexText component.
> Yes, you could actually greatly simplify the original mapping: island attached the following image(s):
|
|
guest |