Importing XML Generically: A Proposed Project

Fairlight fairlite at fairlite.com
Tue Dec 18 13:08:37 PST 2007


With neither thought nor caution, Fairlight blurted:
> xml2csv -c ord.conf [-n namespace] [-o out_file] -r order 20071218113903.xml
> 
> ...and assuming you'd get as output, line after line in the format:
> 
> "12/11/2007","C2987197D25","Mark","Luljak","Yes","995.00","USD","12/12/2007"
> 
> ...Well, then you'd have valid XML translated to a usable CSV format the fP
> can use with IMPORT.  Fields would be presented in the order defined in the
> config file.  You can specify different config files for different data
> files, making this generic.

As someone just pointed out to me on the phone, there is still more
potential to be had, here.  Why allow only generate a CSV for use with
IMPORT?

Proposed option:  -f    Assume foreign file configuration.

Given this option, the config file lines each would require a second field:

transaction.order.billing.amount 12

This would denote that this should be stored in a field 12 characters long.
Effectively, this lets you not just do IMPORT, this lets you instead
(optionally) create an alien file onto which you can lay a map, and all
your data is right there, *boom*.

And I could do it exactly like that, as an -option-, not a complete
overhaul of intent.  Easily.  Couple of conditional sprintf()'s and it's
done.  Actually, once you get the main data correlation down, tacking on
new output formats is relatively trivial.

A lot of people -really- seem to like the alien file overlay trick for
getting their data, so this made sense to me as something to include if I
do the project.  Enough so that I thought it was worth bringing up as a
point of consideration.  Obviously not applicable to things that have an
indefinite amount of detail fields (ie., one-to-many that could exceed a
predetermined length when concatenated), but in many cases this could be
a very expedient way to go.

mark->
-- 
Fairlight->   ||| "This ain't rock 'n roll--this     | Fairlight Consulting
  __/\__      ||| is...genocide!" --Bowie            |
 <__<>__>     |||                                    | http://www.fairlite.com
    \/        |||                                    | info at fairlite.com


More information about the Filepro-list mailing list