in reply to Re^4: DBD:AnyData on Complex XML
in thread DBD:AnyData on Complex XML

Here's an example using Text::CSV and XML::Twig to get you started:
use strict; use warnings; use Text::CSV; use XML::Twig; my $CSV = Text::CSV->new(); my $XML = XML::Twig->new( twig_handlers => { product => sub { my @data; push @data, $_->att('description'); my $c_i = $_->first_child('catalog_item'); push @data, $c_i->att('gender'); ### Gather the other fields here, then... $CSV->print(*STDOUT, \@data); print "\n"; }, }, pretty_print => 'indented', ); $XML->parsestring(*DATA); __DATA__ <?xml version="1.0"?> <?xml-stylesheet href="catalog.xsl" type="text/xsl"?> <!--<!DOCTYPE catalog SYSTEM "catalog.dtd">--> <catalog> <product description="Cardigan Sweater" product_image="cardigan.jpg" +> <catalog_item gender="Men's"> <item_number>QWZ5671</item_number> <price>39.95</price> <size description="Medium"> <color_swatch image="red_cardigan.jpg">Red</color_swatch> <color_swatch image="burgundy_cardigan.jpg">Burgundy</color +_swatch> </size> <size description="Large"> <color_swatch image="red_cardigan.jpg">Red</color_swatch> <color_swatch image="burgundy_cardigan.jpg">Burgundy</color +_swatch> </size> </catalog_item> <catalog_item gender="Women's"> <item_number>RRX9856</item_number> <price>42.50</price> <size description="Small"> <color_swatch image="red_cardigan.jpg">Red</color_swatch> <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> <color_swatch image="burgundy_cardigan.jpg">Burgundy</color +_swatch> </size> <size description="Medium"> <color_swatch image="red_cardigan.jpg">Red</color_swatch> <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> <color_swatch image="burgundy_cardigan.jpg">Burgundy</color +_swatch> <color_swatch image="black_cardigan.jpg">Black</color_swatc +h> </size> <size description="Large"> <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> <color_swatch image="black_cardigan.jpg">Black</color_swatc +h> </size> <size description="Extra Large"> <color_swatch image="burgundy_cardigan.jpg">Burgundy</color +_swatch> <color_swatch image="black_cardigan.jpg">Black</color_swatc +h> </size> </catalog_item> </product> </catalog>