[OSM-dev] Split osm line with perl
Dave Stubbs
osm.list at randomjunk.co.uk
Sun Nov 29 11:52:21 GMT 2009
On Sun, Nov 29, 2009 at 11:41 AM, Lennard <ldp at xs4all.nl> wrote:
> Maarten Deen wrote:
>
>> I've tried a few things, but I'm not fluent in perl. My problem at the moment is
>> that splitting a line on the space character seems logical, but you run into
>> problems if a value has a space in it.
>> So splitting something like <tag k="name" v="foo bar"/> will split the value
>> "foo bar" also.
>
> You have to be fluent in regexes, not perl as such. The trick is to
> match the quote, then to match anything that is not a quote, followed by
> a quote.
And then hope that the attributes are in the order you're expecting,
and that the XML has used " rather than '. And in the example code
given below hope that only one space was used.
If you know the OSM XML source that's probably not such a massive issue.
Don't forget to unescape any XML entities in the key or value as well.
The real trick of course is to use an XML parser which handles all of
this for you.
Dave
More information about the dev
mailing list