LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  More XML Parsing -- this time KML output

    Employee
    Posted 11-24-2013 12:30

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: cpeckham

    Hi!
    This time I am parsing KML output from batchgeo.com.
    Here is a sample (2 records + closing).
    <?xml version="1.0"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><name>Site List with Site Name</name><description> | Created with http://batchgeo.com</description><style id="0"><BalloonStyle><text><![CDATA[ <b>$[name]</b><br />$[address]<br />$[description]<br/><br/>$[geDirections] ]]></text></BalloonStyle></style><Placemark><description>&lt;div&gt;&lt;span class=&quot;l&quot;&gt;Site:&lt;/span&gt;&amp;nbsp;BRHOAL&lt;/div&gt;</description><Point><coordinates>-86.821308387064,33.499887140373,0</coordinates></Point><address>401 6th St S Birmingham, AL </address><styleUrl>#0</styleUrl></Placemark><Placemark><description>&lt;div&gt;&lt;s pan class=&quot;l&quot;&gt;Site:&lt;/span&gt;&amp;nbsp;LTRKAR&lt;/div&gt;</description><Point><coordinates>-92.278127642797,34.746886017451,0</coordinates></Point><address>300 S Gaines Street Little Rock, AR </address><styleUrl>#0</styleUrl></Placemark><Placemark><description>&lt;div&gt;&lt;s pan class=&quot;l&quot;&gt;Site:&lt;/span&gt;&amp;nbsp;PHNXAZ&lt;/div&gt;</description><Point><coordinates>-112.35812226567,33.406499811075,0</coordinates></Point><address>13936 West Broadway Goodyear, AZ </address><styleUrl>#0</styleUrl></Placemark></Document><kml>

    My settings for the Tabular XML File Node:
    RecordXPath: /kml/Document/Placemark
    FieldNameXPath: /kml/Document/Placement/*
    FieldNameFunction: local-name()
    FieldValueXPath: /kml/Document/Placemark/*/text()
    FieldValueFunction: <blank>

    I have also tried to use the regular XMLpy node:
    @elementHandler('/kml/Document/Placemark')
    def EntryHandler(element):
    data = {}
    data['description'] = element.description
    data['Point'] = element.Point.coordinates
    data['address'] = element.address
    outputRecord(data, 0)


    Ignoring the "&" phrases (which I can strip out once I get them into fields), I get no records processed. ("No output produced. No tags matched the RecordXPath expression [/kml/Document/Placemark]. Therefore, no output records were produced.").
    What did I miss? Any suggestions?
    Thanks in advance for your help.
    -cp


  • 2.  RE: More XML Parsing -- this time KML output

    Employee
    Posted 12-06-2013 03:56

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    An update to the Lavastorm Analytic Library (2.16 - compatible with LAE 4.6.1) has just been released along with a new node "XML Data" - see the corresponding post about the update here: http://community.lavastorm.com/threa...he-LAL-library

    The XML Data node should allow you to easily read such XML files with effectively no configuration - all you need to do is point the node at the file you are trying to read.


    I've attached an example graph. The node "No Coonfiguration" does just this.

    If you do only want the fields under the kml/Document/Placemark structure, then the node "Configured to only read kml.Document.Placemark" shows how this can be done.
    Simply change the name of the "Data" output to "kml.Document.Placemark", then on the ExceptionBehavior tab, set the parameter "UnmappedFieldBehavior" to "Ignore".

    In addition, to make sure that the fields aren't all output with the "kml.Document.Placemark" field prefix, I've set "RemoveCommonPrefixes" on the "Optional" tab to true.

    Then I think this is getting exactly the sort of output you want.

    (Note - I took the liberty of changing the XML you attached in your post because it looks like the last <kml> tag should have been </kml>)

    Regards,
    Tim
    Attachments:
    kmlParsing.brg