Click here to get back home

CSV to quasi-XML

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
CSV to quasi-XML Travis 04-14-2008
Posted by Travis on April 14, 2008, 5:30 pm
Please log in for more thread options
Hi there,

Never written a line of Perl until now but I think it might be perfect
for this little program I need.

I have some CSV files that are given to me and I need to spit them in
a format that kind of looks like XML but I don't think it is. The
structure looks something like this:

<ADDRESSES>
<struct>
<field name="First" value="John" />
<field name="Last" value="Doe" />
<field name="City" value="San Francisco" />
</struct><struct>
<field name="First" value="Jane" />
<field name="Last" value="Johnson" />
<field name="City" value="New York City" />
</struct>
</ADDRESSES>


I don't think that's standard XML is it? If so please let me know so I
can change my google searching on the topic.

Anyway, I get CSV's that look something like this:

First,Last,City
John,Doe,San Francisco
Jane,Johnson,New York City


I'm a C/C++ person by nature but I thought this would be a good way to
get my hands in Perl and learn a bit.

Any guidance is helpful. Thanks.

Posted by Travis on April 14, 2008, 5:34 pm
Please log in for more thread options
Oh also there should be a newline \n between the closing </struct> and
the next <struct>

Posted by A. Sinan Unur on April 14, 2008, 5:52 pm
Please log in for more thread options
m:

> Oh also there should be a newline \n between the closing </struct>
> and the next <struct>

I knew I was making a mistake replying. *Sigh*. Just confirmed my
expectations.

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by A. Sinan Unur on April 14, 2008, 5:52 pm
Please log in for more thread options
news:1db6609e-07f3-4388-befb-9088405d95e9
@w4g2000prd.googlegroups.com
:

> Never written a line of Perl until now but I think it might be
> perfect for this little program I need.

It looks you are planning to have someone else write the lines of
Perl that might be needed rather than writing them yourself.

> I have some CSV files that are given to me and I need to spit them
> in a format that kind of looks like XML but I don't think it is.
> The structure looks something like this:
>
> <ADDRESSES>
> <struct>
> <field name="First" value="John" />
> <field name="Last" value="Doe" />
> <field name="City" value="San Francisco" />
> </struct><struct>
> <field name="First" value="Jane" />
> <field name="Last" value="Johnson" />
> <field name="City" value="New York City" />
> </struct>
> </ADDRESSES>
>
>
> I don't think that's standard XML is it?

Of course, it is.

> If so please let me know
> so I can change my google searching on the topic.

Why would searching Google be easier than writing the program in the
first place?

>
> Anyway, I get CSV's that look something like this:
>
> First,Last,City
> John,Doe,San Francisco
> Jane,Johnson,New York City
>
> I'm a C/C++ person by nature

No one is a 'C/C++ person' by nature. If you know C, this is trivial
to write. So, first write the program in C, then read
<URL:http://www.ebb.org/PickingUpPerl/>. You can then come back and
ask if you run into any problems.

> but I thought this would be a good
> way to get my hands in Perl and learn a bit.
>
> Any guidance is helpful. Thanks.

OK, here is a part of a fish:

my ($first, $last, $city) = split /,/, $line;

print <<STRUCT;
<struct>
<field name="First" value="$first" />
<field name="Last" value="$last" />
<field name="City" value="$city" />
</struct>
STRUCT

There is also:

http://csv2xml.sourceforge.net/

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by Travis on April 14, 2008, 5:55 pm
Please log in for more thread options
> news:1db6609e-07f3-4388-befb-9088405d95e9
> @w4g2000prd.googlegroups.com
> :
>
> > Never written a line of Perl until now but I think it might be
> > perfect for this little program I need.
>
> It looks you are planning to have someone else write the lines of
> Perl that might be needed rather than writing them yourself.
>
>
>
> > I have some CSV files that are given to me and I need to spit them
> > in a format that kind of looks like XML but I don't think it is.
> > The structure looks something like this:
>
> > <ADDRESSES>
> > <struct>
> > =A0 =A0 <field name=3D"First" value=3D"John" />
> > =A0 =A0 <field name=3D"Last" value=3D"Doe" />
> > =A0 =A0 <field name=3D"City" value=3D"San Francisco" />
> > </struct><struct>
> > =A0 =A0 <field name=3D"First" value=3D"Jane" />
> > =A0 =A0 <field name=3D"Last" value=3D"Johnson" />
> > =A0 =A0 <field name=3D"City" value=3D"New York City" />
> > </struct>
> > </ADDRESSES>
>
> > I don't think that's standard XML is it?
>
> Of course, it is.
>
> > If so please let me know
> > so I can change my google searching on the topic.
>
> Why would searching Google be easier than writing the program in the
> first place?
>
>
>
> > Anyway, I get CSV's that look something like this:
>
> > First,Last,City
> > John,Doe,San Francisco
> > Jane,Johnson,New York City
>
> > I'm a C/C++ person by nature
>
> No one is a 'C/C++ person' by nature. If you know C, this is trivial
> to write. So, first write the program in C, then read
> <URL:http://www.ebb.org/PickingUpPerl/>. You can then come back and
> ask if you run into any problems.
>
> > but I thought this would be a good
> > way to get my hands in Perl and learn a bit.
>
> > Any guidance is helpful. Thanks.
>
> OK, here is a part of a fish:
>
> my ($first, $last, $city) =3D split /,/, $line;
>
> print <<STRUCT;
> <struct>
> =A0 =A0 <field name=3D"First" value=3D"$first" />
> =A0 =A0 <field name=3D"Last" value=3D"$last" />
> =A0 =A0 <field name=3D"City" value=3D"$city" />
> </struct>
> STRUCT
>
> There is also:
>
> http://csv2xml.sourceforge.net/
>
> Sinan
>
> --
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpm=
isc/

lol thanks for the taste. i appreciate it.


Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap