good day perl-monks today i have a question regarding textmangling and converting.

well i want to use perl for text-mangling - so we can use the XML::Simple module. here's an example of a little script to parse your XML:

see the Code:

#!/usr/bin/perl use strict; use warnings; use XML::Simple; use Data::Dumper; my $xmlfile = shift || die "Usage: $0 <XML_FILE>\n"; my $ref; eval { $ref = XMLin($xmlfile, ForceArray => 0, KeyAttr => [ ], SuppressEmpty => '', ) or die "Can't read XML from $xmlfile: $!\n"; }; die $@ if($@); print Dumper $ref;



Explantion: iterating trough the array / hash - this does create a file and helps carving up the data into comma separated lines of data than can be redirected to file.
<?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Overpass API"> <note>The data included in this document is from www.openstreetmap.org +. The data is made available under ODbL.</note> <meta osm_base=":49:02Z"/> <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="Sofienstraße"/> <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-Württemberg"/> <tag k="addr:street" v="Rohrbacher Straße"/> <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>
i runned this - and it looks nice.. Do you think that this is an appropiate way to do this?

In reply to XML::Simple to parse a xml-file and transform it to csv by Perlbeginner1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.