473,513 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Flat file to XML

Rob

Anyone know of a simple way to convert a UNIX flat file (tab
delimited)with about 20 fields(one header) to a xml file. What I want to
do it to be able to open the file in a spreadsheet easily.

thanks,
-Rob
Apr 6 '07 #1
5 3844
Rob wrote:
Anyone know of a simple way to convert a UNIX flat file (tab
delimited)with about 20 fields(one header) to a xml file. What I want to
do it to be able to open the file in a spreadsheet easily.
With XSLT 2.0 (as implemented by Saxon from <http://www.saxonica.com>)
it should be easy to implement the conversion, using the unparsed-text
function and the tokenize function.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 6 '07 #2
Rob wrote:
What I want to do it to be able to open the file in a spreadsheet easily.
Most spreadsheet programs can already import CSV or TSV files; I'm not
sure why you're going through XML for this specific application.

If you really want to implement your own TSV-to-XML parser, I'd suggest
you consider swiping and adapting the simple CSV parser shown at
http://xerces.apache.org/xerces2-j/x...-parser-config
There's an example of how to invoke it as a SAXParser earlier on that page.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 6 '07 #3
Rob wrote:
>
Anyone know of a simple way to convert a UNIX flat file (tab
delimited)with about 20 fields(one header) to a xml file. What I want to
do it to be able to open the file in a spreadsheet easily.

thanks,
-Rob
Look here :
http://reflex.gforge.inria.fr/tutorial.html#N801B3C

With XPath, you can match your input and create your custom XML structure.
If the "line reader" is not enough, you can also use a regular
expression (read the other examples)

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
Apr 6 '07 #4
Rob
Ok thanks for your quick responses. I want this so the user does not
have to perform any imports on the Excel side.
This below looks promising, but I don't know much about these
applications. I only know how to create simple shell scripts. I may be
able to create one that reads in each line and echoes what I need to
create an xml document. I think I'm going to have to do something like that.

-Rob

Philippe Poulard wrote:
Rob wrote:
>>
Anyone know of a simple way to convert a UNIX flat file (tab
delimited)with about 20 fields(one header) to a xml file. What I want
to do it to be able to open the file in a spreadsheet easily.

thanks,
-Rob

Look here :
http://reflex.gforge.inria.fr/tutorial.html#N801B3C

With XPath, you can match your input and create your custom XML structure.
If the "line reader" is not enough, you can also use a regular
expression (read the other examples)
Apr 6 '07 #5
Rob <ro******@bellsofthesouth.netwrites:
Ok thanks for your quick responses. I want this so the user does not
have to perform any imports on the Excel side.
This below looks promising, but I don't know much about these
applications. I only know how to create simple shell scripts. I may
be able to create one that reads in each line and echoes what I need
to create an xml document. I think I'm going to have to do something
like that.
Do you know awk? Here is a small awk command that will output
something that _may_ be well-formed XML (assuming the first line
contains field names). Adapt at your will, be careful with encodings
and quoting in the initial data, plug in your specific tags. And don't
expect too much.

awk -F'\t' '
BEGIN { printf("<file>\n"); }
NR==1 {
for ( i=1 ; i<=NF ; i++ )
name[i] = $i;
}
NR>1 {
for ( i=1 ; i<=NF ; i++ )
printf("<%s>%s</%s>\n",name[i],$i,name[i]);
}
END { printf("</file>\n"); }
' yourfile.csv

-- Alain.

Apr 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3397
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm...
1
2180
by: Tim Fierro | last post by:
Hello, I have had many years using flat file databases (File Express from way back) but am now at a company where a relational database is needed and would carry us into the future. Since I...
22
2977
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
4
1705
by: Ben | last post by:
So, at my place of employment, we use a national standard to transmit data between certain applications. This standard consists of a fixed width, flat file 4500-some-odd chars wide that contain...
2
2630
by: Neural | last post by:
Hi, I was wondering if anybody knew of any other ways of efficiently parsing a flat file into SQL Server 2000 using C#. The flat files are tab delimited. And the general file size is around 1 GB...
14
2247
by: vunet.us | last post by:
Hi, I would like to use flat file data storage instead of database. Since I am new to it, I am wondering: What text file extension is a safe one to store my data online and how cost- and...
9
2180
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As...
2
6119
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during...
5
4855
by: Gorilla3D | last post by:
I've writing my own flat file database.. well table-based pure php code, PhpSimpleDb but I was looking into some bench marking so was wonder if anyone knew any other flat-file php db's out there. ...
15
5241
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.