Question

KML to FME attribut

  • 29 July 2019
  • 1 reply
  • 4 views

Badge

Hello,

 

I want to do the same operation like this tutorial : https://knowledge.safe.com/articles/19918/how-to-expose-feature-attributes-from-kml-tag.html or this topic : https://knowledge.safe.com/questions/29326/how-can-i-extract-the-html-table-from-kml-descript.html

It consits in expose feature attributes from KML tag.

I've done the step with HTMLtoWHTMLconverter and I obtaint this :

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
</head>

<body>
  Survey Parameters<br />
  <br />
  <hr />

  <table border="0" padding="10">
    <tr>
      <td></td>
      <td>Planned</td>
      <td>Current</td>
      <td>Desired</td>
    </tr>
    <tr>
      <td>Scan Frequency [Hz]</td>
      <td>66</td>
      <td>66</td>
      <td>66</td>
    </tr>
    <tr>
    ... I VOLUNTARY NOT DISPLAY ALL THE LINES
       <td>Speed [m/s]</td>

      <td>67</td>

      <td>62</td>

      <td></td>
    </tr>
  </table><br />
</body>
</html>

Then in XMLXQueryExtractor I adapt the request and I write this :

    declare default element namespace "http://www.w3.org/1999/xhtml";
    for $x in /body/div/table
    for $y in $x/tr
    return fme:set-attribute($y/th/text(), $y/td/text())

But in query results I don't have any new attribut, it doen't work...

I think that the solution is a little modification of the query but I don't know how to do , do you have any idea ?

 

Arnaud


1 reply

Userlevel 3
Badge +17

Hi @arnaudfouch

The XQuery snippet you have posted is for a KML table with a different structure. Based on the snippet you posted, you will need to change from /body/div/table to /html/body/table/tr

In addition, your KML table is structured differently with 4 columns rather than 2 columns as is normally found in KML description tags. As a starting point, you can try the following XQuery:

declare default element namespace "http://www.w3.org/1999/xhtml";
for $c in 2 to 4
for $x in /html/body/table/tr
let $ind := /html/body/table/tr[1]
let $attrName := string-join(($x/td[1]/text(),(string($ind/td[$c]/text()))),".")
return fme:set-attribute($attrName, $x/td[$c]/text())

The above XQuery should create list-like attribute names for your elements depending on the 'type' (eg. Scan Frequency [Hz].Current, Scan Frequency [Hz].Planned, etc.). Depending on your actual KML description tag output, you may need to modify this XQuery.

Reply