[OSM-dev] Escaping special characters when writing tags in OSM files with osm-subset.pl & write.pm

Dave osm at randomjunk.co.uk
Sun Nov 5 23:11:49 GMT 2006


& should ALWAYS be escaped in XML. That's because & IS the XML escape
character.
So if you want a raw & it's &

>From http://www.w3.org/TR/2006/REC-xml-20060816/#syntax :

'The ampersand character (&) and the left angle bracket (<) *MUST
NOT*appear in their literal form, except when used as markup
delimiters, or
within a comment <http://www.w3.org/TR/2006/REC-xml-20060816/#dt-comment>, a
processing instruction <http://www.w3.org/TR/2006/REC-xml-20060816/#dt-pi>,
or a CDATA section<http://www.w3.org/TR/2006/REC-xml-20060816/#dt-cdsection>.
If they are needed elsewhere, they *MUST* be
escaped<http://www.w3.org/TR/2006/REC-xml-20060816/#dt-escape>using
either numeric
character references<http://www.w3.org/TR/2006/REC-xml-20060816/#dt-charref>or
the strings "
&" and "<" respectively.'

On 05/11/06, Dean Earley <dean at earlsoft.co.uk> wrote:
>
> Jon Burgess wrote:
> > I've found that both osm-subset.pl and Geo::OSM::Write fail to escape
> > characters like " & ' in tags leading to problem when trying to parse
> > the OSM that they write.
> >
> > The attached patches made them work for me although I still seem to be
> > seeing some UTF-8 related issues (though UTF8sanitizer fixes these up).
> > Does anyone know if there is a better way to be generating valid XML?
> >
> > The patch to osm-subset.pl also fixes it to work with .bz2 compressed
> > planet.osm files.
>
> From memory, & SHOULDN'T be escaped in XML files.
> I was surprised when I read this but it fixed my RSS feed.. :)
>
> --
> Dean Earley, Dee (dean at earlsoft.co.uk)
>
> irc:    irc://irc.blitzed.org/
> web:    http://personal.earlsoft.co.uk
> phone:  +44 (0)780 8369596
>
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20061105/6747b7d7/attachment.html>


More information about the dev mailing list