Question

Error &-character when reading kml-file

  • 13 February 2017
  • 4 replies
  • 9 views

Hello all,

Last year i posted a question here on reading a descripton of a kml-file. This is a new question with the same background: reading a kml-file that contains data from an app (BuitenBeter) that people can use to inform the city about all kinds of things in public space.

Some of these kml-files, like the one attached, have a &-character in the kml-description that results in an error: XML Parser error: 'Error in input dataset:'file...MOR 020816-140816.kml' line:1 column:58047 message:expected entity name for reference'. The script continues with the next file, but this file is now only partially read. I get the same (kind of) error when using the XML and KML reader and using FME versions 2014 en 2016. The error refers to a &-character that can be found in some descriptions. Till now i replaced this &-character manually, but now i'm working on a automatic script for which it is important to get a 'real' solution to this problem.

So, does anyone know how to read kml-files, with an &-character in the description, without errors?. As i got some useful remarks last year, i hope someone is able to help me with this one. Thanks in advance.

Greetings,

Antoon van Ham

City of Eindhoven, Netherlands


4 replies

Userlevel 4

The ampersand "&" is not a legal character in XML (KML is a subset of XML, so the same rules apply).

You will have to replace all the "&" with "&" inside your file, FME should be able to read it just fine then:

Badge +2

The ampersand "&" is not a legal character in XML (KML is a subset of XML, so the same rules apply).

You will have to replace all the "&" with "&" inside your file, FME should be able to read it just fine then:

What david_r is saying is correct. I tried the following on your KML and got it to open fine.

 

Right click on the KML and open with notepad(kladlok). Edit (bewerken) -> replace (vervangen). Add & in "search for (zoeken naar)" and & in "replace by (vervangen door)" than hit replace or replace all (alles vervangen) depanding on the fact if there are already & in the dataset.

 

 

In your kml it should replace 2 objects and adfter that it should work fine.

 

 

Userlevel 4

If you need to automate the correction of your KML file, you can create a separate workspace using a Text File reader/writer combination and the following StringReplacer in between:

0684Q00000ArLEqQAN.png

Be sure to set "use regular expressions" to yes. Here's the regex for copy/paste purposes:

&(?!(?:apos|quot|[gl]t|amp);|#)

You could then e.g. chain your workspaces together using a master workspace and a couple of WorkspaceRunner transformers. Alternatively you can do it all in a single workspace with some clever use of the FeatureReader.

Thank you for your quick answers/comment. Especially the last one was helpful as it is needed to be implemented in a FME-script. It will be part of process thats gonna be scheduled every weekend.

With help of a colleague there is now one workspace in which the kml-files are read as text-files, followed with the StringReplacer and written again as textfiles with an kml-extension and in a new directory. The writer is followed by a FileReader where the kml-files are read as xml-files (due to the earlier problem with the description). Now all records are read without the XML Parser error and processed.

Reply