Skip to main content

Hi,

 

I am trying to extract atributes from a KML file (FME Desktopm 2014 Build 14289). I read the example on FMEpedia but my KML is formated slightly differently and no matter what I try I can't figure it out.

 

 

The KML description, once processed by the HTMLToXHTMLConverter, looks like:

 

 <!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>

 

  CBM No: <b>527008</b><br />

 

  <br />

 

  <br />

  <table border="1" padding="0">

 

    <tr bgcolor="#DCDCDC">

 

      <th colspan="2">

 

        <center>

 

          Station Info

 

        </center>

 

      </th>

 

    </tr>

    <tr bgcolor="#FFFFD6">

 

      <td><font size="2">CBM_NO</font></td>

      <td><font color="#00008B" size="2">527008</font></td>

 

    </tr>

    <tr bgcolor="#E0FFFF">

 

      <td><font size="2">AWRC_NO</font></td>

      <td><font color="#00008B" size="2">922101</font></td>

 

    </tr>

    <tr bgcolor="#FFFFD6">

 

      <td><font size="2">STN_NAME</font></td>

      <td><font color="#00008B" size="2">COEN RACECOURSE

 

      TM</font></td>

 

    </tr>

 

 

The attributes are within the <td> elements of the <tr> node. However, the first <tr> is structured differently to the other <tr> nodes which seems to create the problem.

 

 

The XQuery expression I'm using is

 

declare default element namespace "http://www.w3.org/1999/xhtml";

 

for $x in /html/body/table/tr

 

return fme:set-attribute($x/tda1]/text(),$x/tdt2]/text())

 

 

This returns the following notes within the log file:

 

XQueryExtractor(XQueryFactory): Caught an exception while executing query: `declare default element namespace "http://www.w3.org/1999/xhtml";

for $x in /html/body/table/tr

return fme:set-attribute($x/tdh1]/text(),$x/tdl2]/text())'

XQueryExtractor(XQueryFactory): No results will be returned for this query

XQueryExtractor(XQueryFactory): The following error occurred near line 3, column 8 of the query:

XQueryExtractor(XQueryFactory): empty-sequence() can not be promoted to parameter type xs:string of function fme:set-attribute()

 

 

Any help would be greatly appreciated.

 

 

Dave

 

For reading KML, we would typically recommend usage of the KML reader itself which typically is able to extract attribution without any need for customisation.

 

 

The <table> contents if not picked up as user attributes, may be picked up in a format attribute such as the kml_description, which could then be parsed via transformers.

 

 

Alternatively, if you prefer reading it in as XML, are you aware of the XMLFlattener and XMLFragmenter transformers? Typically using them can greatly assist in breaking up xml files akin to what you are trying to do.

 

 

I'd highly recommend trying either of the above approaches before looking further into xquery.

Reply