Field delimited data to XML


 
Thread Tools Search this Thread
Top Forums Programming Field delimited data to XML
# 8  
Old 12-10-2013
Quote:
Originally Posted by Indalecio
I'm wondering where to store the mapping configuration so it can be picked up by the program rather than relying on a large number of conditional statements based on the record key value and the field_ID to deduce the tags to use.
Well, please let us know when you do. Until your data format stops changing, writing a program for it will be a waste of time.

You could use blank lines to separate different objects perhaps.
Quote:
My initial approach was to break down the original input structure to form a file with one line per field comprising of the Record/Field ID and the value, then replace the Record/Field ID by it's corresponding XML tag and finally wrap it up all together. At this point awk should be able to deal with it. The question is how long it takes to process 100.000s of "objects".
awk is pretty good at processing large amounts of text. That's what its designed for after all.
Quote:
About the comment on the fact picking a language comes down to personal preference, I mean I can not disagree with that but when you look at performance some languages will deal with this requirement faster than others.
This is true. It's still possible to write bad, slow code in any language, though -- not to mention, reinvent the wheel. I recall a thread like this where the poster was in essence reinventing awk slowly, painfully, and badly, refusing all suggestions of better solutions because he wanted to use a 'fast language'. Well, awk is written in C++ too.

Last edited by Corona688; 12-10-2013 at 11:37 AM..
# 9  
Old 12-11-2013
I appreciate the feedback. I know what you mean by people trying to reinvent the wheel, it's hard to stop them once they´re convinced their idea is the solution they should go for. But if they don't even take criticism then it's even a worse thing! I think of this as some kind of syndrome where the coder just mentally shuts off and ignores all incoming information to exclusively focus on a unnecessarly complex and technical approach.

Re-writing programs in more efficient/easier to maintain languages as new powerful tools are getting released is something I´ve always kept an eye on. The challenge of course is to find a budget for purely technical upgrades. Very often you need a functional/business requirement to justify such rewrite.

About the original query, I mean I´ll just go for awk (which I´m confortable with anyway) and store all the mappings in a control file. There will be new tags, new fields added/changed in the future so I'll try to keep this configurable, maybe by making this file as a periodic report from a GUI screen where some key users can change the settings. As always, depends on how much intelligence people want to throw into that thing.
# 10  
Old 12-11-2013
In this example, the first column, e.g., Record_key_1, did not find a home inside the xml. Many attributes, being unique at their level, are more compactly stored in Attributes of the Element, not contained in an element.
Code:
<OuterWrapper>
  <Record ID=Record_key_1>
    <Item col=1 val=A/>
    <Item col=2 val=B/>
    <Item col=3 val=C/>
   </Record>
 .
 .
 .
 </OuterWrapper>

Double quotes are necessary when attribute values have embedded whitespace, and url-encoding if containing: " < > ' & ( &quot; &lt; &gt; &apos; &amp; )
http://en.wikipedia.org/wiki/XML#Escaping

Last edited by DGPickett; 12-11-2013 at 04:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace field in the delimited file

Hi, I have the requirement similar to the one mentioned in the below thread. https://www.unix.com/unix-for-dummies-questions-and-answers/128155-search-replace-string-only-particular-column-delimited-file.html The only difference is that I need to change the field for row 1,2 and the last... (14 Replies)
Discussion started by: chetanojha
14 Replies

2. Shell Programming and Scripting

How can i comma-delimited last field in line?

Awk gurus, Greatly appreciate for any kind of assistance from the expert community Input line: abc,11.22.33.44,xyz,7-8-9-10 pqr,111.222.333.444,wxy,1-2-3 def,22.33.44.55,stu,7-8 used the gsub function below but it changes all of the "-" delimiter: awk 'gsub("-",",")' Desired... (4 Replies)
Discussion started by: ux4me
4 Replies

3. Shell Programming and Scripting

Remove Last field from a delimited file

Hi, I have a '~' delimited file and i want to remove the last field using awk. Please find the sample records below: 1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~14~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110423~R~ ~0~Z~1662.94~ ~002041~0045~Z~... (3 Replies)
Discussion started by: Arun Mishra
3 Replies

4. Shell Programming and Scripting

Cgi to dump xml data from form input field

Hi All, I am trying to write a shell script which takes parse the web form find the input field and dump the data of that field into one xml file. The form looks like, <input type="button" id="btnSave" value="Save" onclick="saveXmlData()"/> <form name="submitForm"... (1 Reply)
Discussion started by: jdp
1 Replies

5. Shell Programming and Scripting

Pad zeroes first field in a Delimited file

Need help. I tried using an awk command to pad zeroes. Unfortunately, the "|" pipe delimited character is gone when I tried to write the records to another file. awk -F \| ' {$1=sprintf("%06s", $1); print $0}' $CUSTFINAL2 > $CUSTFINAL3 BEFORE "KEYRECORD"|"SA ID"|"PER ID"|"SP ID"|"ACCT... (3 Replies)
Discussion started by: johnhips
3 Replies

6. Shell Programming and Scripting

Using AWK to parse a delimited field

Hi everyone! How can I parse a delimited field using AWK? For example, if I have lastName#firstName or lastName*firstName. I'd like an AWK script that would return lastName and then another that would return firstName? Is this possible? (13 Replies)
Discussion started by: Fatbob
13 Replies

7. Shell Programming and Scripting

insert a field into a tab delimited file

Hello, Can someone help me to do this with awk or sed? I have a file with multiple lines, each line has many fields separated with a tab. I would like to add one more field holding 'na' in between the first and second fields. old file looks like, 1, field1 field2 field3 ... 2, field1... (7 Replies)
Discussion started by: ssshen
7 Replies

8. Shell Programming and Scripting

Count field frequency in a '|' delimited file

I have a large file with fields delimited by '|', and I want to run some analysis on it. What I want to do is count how many times each field is populated, or list the frequency of population for each field. I am in a Sun OS environment. Thanks, - CB (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

9. Shell Programming and Scripting

How to perfrom summation for particular delimited field?

Hi, Please help to share your thought about how to perfrom summation for particular delimited field, and output to the particular file based on -rw-r--r-- 1 abc other 3094 Oct 19 09:40 0132019832-ps5_online_cdrm.unl -rw-r--r-- 1 abc other 1588 Oct 19 09:47... (2 Replies)
Discussion started by: rauphelhunter
2 Replies
Login or Register to Ask a Question