Skip to main content
Solved

Extracting attributes from a KML in odd format


Hello, 

 

I am having issues extracting info from a kml. Here is how the information is stored in the kml_description. What kind of transformer would I use to extract the info.

 

<style type="text/css">td {white-space:nowrapth {align:lefttd.padr {padding-right:0.5cm}</style><table><tr><th></th><th></th></tr><tr><td class="padr">GPS Date:</td><td>03/29/17</td></tr><tr><td class="padr">GPS Time:</td><td>02:26:15pm</td></tr><tr><td class="padr">Datafile:</td><td>R032913A.cor</td></tr><tr><td class="padr">Avg Horz Prec:</td><td>0.9</td></tr><tr><td class="padr">Worst Horz Prec:</td><td>1.2</td></tr></table>

 

Best answer by daveatsafe

Hi @dchow​,

FME doesn't have a transformer to extract the table data from HTML, but it does have a reader that can. So you can write the kml_description attribute to a temporary file, then read it back in through a FeatureReader:

Screen Shot 2023-05-25 at 2.00.38 PMI have attached the workspace snippet for you. It could be wrapped up in a custom transformer if there is enough interest. The folder created by the TempPathnameCreator is automatically cleaned up when the workspace finishes.

View original
Did this help you find an answer to your question?

8 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • Best Answer
  • May 25, 2023

Hi @dchow​,

FME doesn't have a transformer to extract the table data from HTML, but it does have a reader that can. So you can write the kml_description attribute to a temporary file, then read it back in through a FeatureReader:

Screen Shot 2023-05-25 at 2.00.38 PMI have attached the workspace snippet for you. It could be wrapped up in a custom transformer if there is enough interest. The folder created by the TempPathnameCreator is automatically cleaned up when the workspace finishes.


  • Author
  • May 30, 2023
daveatsafe wrote:

Hi @dchow​,

FME doesn't have a transformer to extract the table data from HTML, but it does have a reader that can. So you can write the kml_description attribute to a temporary file, then read it back in through a FeatureReader:

Screen Shot 2023-05-25 at 2.00.38 PMI have attached the workspace snippet for you. It could be wrapped up in a custom transformer if there is enough interest. The folder created by the TempPathnameCreator is automatically cleaned up when the workspace finishes.

Hi @daveatsafe​ 

 

When I run the workflow at the FeatureReader I get an error "HTML Table Reader: No lists or tables were found in the HTML document".

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • May 30, 2023
dchow wrote:

Hi @daveatsafe​ 

 

When I run the workflow at the FeatureReader I get an error "HTML Table Reader: No lists or tables were found in the HTML document".

 

Because the temporary folder lasts only as long as the workspace is running, I don't think this workspace will work properly with Feature Caching. Please use Run - Run Entire Workspace to run the full workspace every time.


  • Author
  • May 30, 2023
dchow wrote:

Hi @daveatsafe​ 

 

When I run the workflow at the FeatureReader I get an error "HTML Table Reader: No lists or tables were found in the HTML document".

 

Hi @daveatsafe​ 

 

Is there an email I can send the data to you with to test with. I've ran it using Run Entire Workspace but I am not getting attributes in the the fields that were exposed.


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • May 30, 2023
dchow wrote:

Hi @daveatsafe​ 

 

When I run the workflow at the FeatureReader I get an error "HTML Table Reader: No lists or tables were found in the HTML document".

 

Sure, please send the data to dave.campanas@safe.com.


ebygomm
Influencer
Forum|alt.badge.img+38
  • Influencer
  • June 1, 2023

You could look at using a HTML extractor to get the table information, if the table is always in the same format

image.png 


ebygomm
Influencer
Forum|alt.badge.img+38
  • Influencer
  • June 1, 2023

You could also use the method described here

 

https://community.safe.com/s/article/how-to-expose-feature-attributes-from-kml-tag

 

with the following xquery

declare default element namespace "http://www.w3.org/1999/xhtml";
for $x in /html/body/table/tr 
return {
 if ($x/td[1] ne ''then fme:set-attribute($x/td[1]/text(),$x/td[2]/text()) 
 else ()
 }

image


  • Author
  • June 1, 2023
ebygomm wrote:

You could also use the method described here

 

https://community.safe.com/s/article/how-to-expose-feature-attributes-from-kml-tag

 

with the following xquery

declare default element namespace "http://www.w3.org/1999/xhtml";
for $x in /html/body/table/tr 
return {
 if ($x/td[1] ne ''then fme:set-attribute($x/td[1]/text(),$x/td[2]/text()) 
 else ()
 }

image

Hi @ebygomm​ ,

 

Those are great examples, I worked with Dave and we figured out a solution using the above workspace, the data had a mix of tables in the description. 

 

But I will keep these examples and try them out.

 

Thanks


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings