nested xml to csv using xmlstarlet -


i trying access content xml file (downloaded local weather service), has following format:

product/observations product/observations/station[@wmo-id='95936' , @bom-id='086338' , @tz='australia/melbourne' , @stn-name='melbourne (olympic park)' , @stn-height='7.53' , @type='aws' , @lat='-37.8255' , @lon='144.9816' , @forecast-district-id='vic_pw007' , @description='melbourne (olympic park)'] product/observations/station/period[@index='0' , @time-utc='2015-05-29t09:20:00+00:00' , @time-local='2015-05-29t19:20:00+10:00' , @wind-src='omd'] product/observations/station/period/level[@index='0' , @type='surface'] product/observations/station/period/level/element[@units='celsius' , @type='apparent_temp'] product/observations/station/period/level/element[@units='celsius' , @type='delta_t'] product/observations/station/period/level/element[@units='km/h' , @type='gust_kmh'] product/observations/station/period/level/element[@units='knots' , @type='wind_gust_spd'] product/observations/station/period/level/element[@units='celsius' , @type='air_temperature'] product/observations/station/period/level/element[@units='celsius' , @type='dew_point'] product/observations/station/period/level/element[@units='hpa' , @type='pres'] product/observations/station/period/level/element[@units='hpa' , @type='qnh_pres'] product/observations/station/period/level/element[@units='%' , @type='rel-humidity'] product/observations/station/period/level/element[@type='wind_dir'] product/observations/station/period/level/element[@units='deg' , @type='wind_dir_deg'] product/observations/station/period/level/element[@units='km/h' , @type='wind_spd_kmh'] product/observations/station/period/level/element[@units='knots' , @type='wind_spd'] 

my interest accessing values associated each element.

i've been experimenting xmlstarlet, , following script can batch process , extract of @wmo-id related xml file.

#!/bin/bash inp=$1 outp=$2 xml="xmlstarlet" xpath="/product/observations/station/period/level" $xml sel -t -t -m $xpath -v "concat(../../@wmo-id,',',../..@stn-name)"     -n $inp > $outp exit 0 

i tried use following extract data 1 of elements no data:

#!/bin/bash xmlfile=$1 xml="xmlstarlet" xpath="/product/observations/stations/period/level"  $xml sel -t -t -m $xpath -v "concat(element[@type='apparent_temp'])" -n $xmlfile  exit 0 

can advise on missing?


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -