in reply to XML::Simple to parse a xml-file and transform it to csv

Hello, as always i suggest XML::Twig

I'm not an XML expert so i confess i found some probelm in your data example, german char included..
I put the modified data in a file. You can see the content after the __END__ token in the script:
use strict; use warnings; use XML::Twig; my $t= XML::Twig->new( pretty_print => 'indented', twig_handlers => { 'node'=>sub{print $_[1]->att('id'),', ',$_[1 +]->att('lat'),', ',$_[1]->att('lon'),', ' ; foreach my $tag ( $_[1]->childre +n ){ print $tag->att('v').", +"; } print "\n"; }, } ); print "#ID, LAT, LON, CITY, HOUSNUMBER, POSTCODE, STREET, NAME, PHONE, + SHOP, SOURCE, WEBSITE, WHEELCHAIR\n"; $t->parsefile('xml-001.xml'); __END__ <?xml version="1.0" encoding="UTF-8"?> <root> <node id="297467" lat="49.5014" lon="8.1465"> <tag k="addr:city" v="Stuttgart"/> <tag k="addr:housenumber" v="23"/> <tag k="addr:postcode" v="69115"/> <tag k="addr:street" v="Sofienstrae"/> <tag k="name" v="ARLT"/> <tag k="phone" v="+49 6221 20229"/> <tag k="shop" v="computer"/> <tag k="source" v="survey"/> <tag k="website" v="http://www.arlt.com"/> <tag k="wheelchair" v="yes"/> </node> <node id="305144906" lat="49.40012" lon="8.6929652"> <tag k="addr:city" v="Mainz"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="13-15"/> <tag k="addr:postcode" v="69115"/> <tag k="addr:state" v="Baden-WUrttemberg"/> <tag k="addr:street" v="Rohrbacher StraSSe"/> <tag k="name" v="Heidel-bike"/> <tag k="opening_hours" v="Tu-Fr 10:00-18:30; Sa 10:00-14:00"/> <tag k="shop" v="bicycle"/> <tag k="website" v="http://www.heidelbike.de/"/> <tag k="wheelchair" v="yes"/> </node> </root> __OUTPUT__ #ID, LAT, LON, CITY, HOUSNUMBER, POSTCODE, STREET, NAME, PHONE, SHOP, +SOURCE, WEBSITE, WHEELCHAIR 297467, 49.5014, 8.1465, Stuttgart, 23, 69115, Sofienstrae, ARLT, +49 +6221 20229, computer, survey, http://www.arlt.com, yes, 305144906, 49.40012, 8.6929652, Mainz, DE, 13-15, 69115, Baden-WUrttem +berg, Rohrbacher StraSSe, Heidel-bike, Tu-Fr 10:00 -18:30; Sa 10:00-14:00, bicycle, http://www.heidelbike.de/, yes,
..and an handful of links from my homenode:
XML "If you need to deal with XML, first, we’re very sorry." b d foy http://www.effectiveperlprogramming.com/2011/07/rewrite-xml-with-xmltwig/ and http://www.effectiveperlprogramming.com/2010/03/process-xml-data-with-xmltwig/ and http://it-is-etc.blogspot.it/2012/07/perl-how-to-manipulate-xml-files-using.html and http://perlmeme.org/tutorials/parsing_xml.html speed comparison http://www.robinclarke.net/archives/xml-parsing-with-perl mirod schratchpad and Re: Another simple XML Twig question and http://www.xml.com/pub/a/2001/03/21/xmltwig.html ambrus's Do not reinvent the wheel: real-world example using XML::Twig and also http://perl-xml.sourceforge.net/faq/ and choroba about XML

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: XML::Simple to parse a xml-file and transform it to csv
by Perlbeginner1 (Scribe) on May 14, 2014 at 18:36 UTC
    hello many many thanks for all!!