l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2010 Jul 15 18:23

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Fwd: Re: complex XML to CSV via XSLT
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Fwd: Re: complex XML to CSV via XSLT

And again


----- Forwarded message from vox-tech-bounces@lists.lugod.org -----

Date: Wed, 14 Jul 2010 17:38:18 -0700
From: vox-tech-bounces@lists.lugod.org
Subject: Auto-discard notification
To: vox-tech-owner@lists.lugod.org

The attached message has been automatically discarded.
Date: Wed, 14 Jul 2010 16:43:24 -0700
From: Dylan Beaudette <debeaudette@ucdavis.edu>
Subject: Re: [vox-tech] complex XML to CSV via XSLT
To: vox-tech@lists.lugod.org
Cc: Wes Hardaker <wjhns156@hardakers.net>
Reply-To: debeaudette@ucdavis.edu

Wow. Pretty neat. Looks like that almost works. It does not work when there 
are several 'pedons' in the collection. 


On Wednesday 14 July 2010, Wes Hardaker wrote:
> >>>>> On Wed, 14 Jul 2010 11:40:35 -0700, Dylan Beaudette
> >>>>> <debeaudette@ucdavis.edu> said:
> DB> I would like to generalize some sample XSLT documents to convert the
> DB> entire file into a sequence of CSV files.
> Remember, that whatever you do in another language you can do in perl
> with less code and more obfuscation:
>   use XML::Simple;
>   use IO::File;
>   use strict;
>   my $doc = XMLin($ARGV[0], SuppressEmpty => '', KeyAttr => 'foobarbogus');
>   my %iohandles;
>   $doc = $doc->{'pedon'};
>   foreach my $key (keys(%$doc)) {
>       if (!exists($iohandles{$key})) {
>   	die "I'm being hacked" if ($key !~ /^[_a-zA-Z0-9]/);
>   	$iohandles{$key} = new IO::File;
>   	$iohandles{$key}->open(">$key.csv");
>   	print STDERR "writing out $key.csv\n";
>       }
>       if (ref($doc->{$key}) ne 'HASH') {
>   	next;
>       }
>       foreach my $subkey (keys(%{$doc->{$key}})) {
>   	if (ref($doc->{$key}{$subkey}) ne 'ARRAY') {
>   	    if (ref($doc->{$key}{$subkey}) ne 'HASH') {
>   		print STDERR "{$key}{$subkey} unexpected type\n";
>   		last;
>   	    }
>   	    $doc->{$key}{$subkey} = [$doc->{$key}{$subkey}];
>   	}
>   	foreach my $record (@{$doc->{$key}{$subkey}}) {
>   	    $iohandles{$key}->print(join(",",values(%$record)),"\n");
>   	}
>       }
>   }
> # perl hack.pl pedons.xml
> writing out hz_mottles.csv
> writing out hz_frags.csv
> writing out horizon.csv
> writing out hz_roots.csv
> writing out memo.csv
> writing out description.csv
> {description}{surface_frags_bd} unexpected type
> writing out hz_pores.csv
> writing out hz_pvsf.csv
> writing out notes.csv
> writing out hz_rmf.csv
> writing out diagnostic.csv
> writing out vegetation.csv
> writing out pedon_spatial.csv
> {pedon_spatial}{y} unexpected type

Dylan Beaudette
Soil Resource Laboratory
University of California at Davis

----- End forwarded message -----

Sent from my computer
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.