Package: xml2
Version: 0.4-2
Followup-For: Bug #506788

Hi,

by examining the source code I've been able to figure out a little more about 
these two
undocumented commands.

both take -q and -d options to set the quoting char and the delimiter char.
e.g. to quote with a single char and a pipe for the delimiter:  -q"'" -d'|' 

csv2 takes an additional -f flag which does something with the first record


usage of 2csv: the 'record' option is the base string, NOT starting with /,
the fields are the "subdirs" under that you want to output.
It seems to get lost if the "record" string is non-unique, e.g. below if I
use 'event' as the record string it gets lost because of 'eventParameters',
but if I use 'origin' that's ok because it's not a substring of anything else.
using the whole thing back to the start (expect the leading / at the start of
the line) seems the safest thing to do.


for example, an extract of XML earthquakes from GNS NZ:

URL="http://magma.geonet.org.nz/services/quake/quakeml/1.0.1/query?";
END_DATE=`date --utc +%FT%T`
START_DATE=`date --utc --date="last week" +%FT%T`
wget -nv -O latest_gns_quakes.xml -nv \
   "${URL}startDate=$START_DATE&endDate=$END_DATE"


"""
1 record of data (1 earthquake event) from that looks like this after going 
through xml2:
/quakeml/eventParameters/event
/quakeml/eventParameters/event/@publicID=smi:geonet.org.nz/event/3446915g
/quakeml/eventParameters/event/type=earthquake
/quakeml/eventParameters/event/preferredOriginID=smi:geonet.org.nz/ori/479264/GROPE
/quakeml/eventParameters/event/preferredMagnitudeID=smi:geonet.org.nz/mag/479264/GROPE/ML
/quakeml/eventParameters/event/origin/@publicID=smi:geonet.org.nz/ori/479264/GROPE
/quakeml/eventParameters/event/origin/type=hypocenter
/quakeml/eventParameters/event/origin/evaluationMode=manual
/quakeml/eventParameters/event/origin/evaluationStatus=confirmed
/quakeml/eventParameters/event/origin/referenceSystemID=smi:ogc.def.crs/EPSG/4272
/quakeml/eventParameters/event/origin/time/value=2011-01-13T05:43:34.182Z
/quakeml/eventParameters/event/origin/time/uncertainty=0.54998
/quakeml/eventParameters/event/origin/latitude/value=-41.86799
/quakeml/eventParameters/event/origin/latitude/uncertainty=0.05634
/quakeml/eventParameters/event/origin/longitude/value=173.7475
/quakeml/eventParameters/event/origin/longitude/uncertainty=0.03236
/quakeml/eventParameters/event/origin/depth/value=46.4401
/quakeml/eventParameters/event/origin/depth/uncertainty=5.0094
/quakeml/eventParameters/event/origin/depthType=from location
/quakeml/eventParameters/event/origin/quality/azimuthalGap=238
/quakeml/eventParameters/event/origin/quality/minimumDistance=19.9
/quakeml/eventParameters/event/origin/quality/maximumDistance=154.21
/quakeml/eventParameters/event/origin/quality/usedPhaseCount=7
/quakeml/eventParameters/event/origin/quality/usedStationCount=5
/quakeml/eventParameters/event/origin/quality/standardError=0.30616
/quakeml/eventParameters/event/magnitude/@publicID=smi:geonet.org.nz/mag/479264/GROPE/ML
/quakeml/eventParameters/event/magnitude/mag/value=2.061
/quakeml/eventParameters/event/magnitude/mag/uncertainty=0.211
/quakeml/eventParameters/event/magnitude/type=ML
/quakeml/eventParameters/event/magnitude/stationCount=3
/quakeml/eventParameters/event/magnitude/originID=smi:geonet.org.nz/ori/479264/GROPE
"""


# process with 2csv:

BASE="quakeml/eventParameters/event"
FIELDS="
origin/time/value
origin/longitude/value
origin/latitude/value
magnitude/mag/value
origin/depth/value
"

xml2 < latest_gns_quakes.xml | 2csv -d'|' $BASE $FIELDS > latest_gns_quakes.csv


and you get nice output like:
....
2011-01-18T20:53:42.376Z|172.17737|-43.49577|2.99|8.6459
2011-01-18T21:01:26.694Z|176.80443|-39.3082|2.785|12
2011-01-19T00:56:45.661Z|172.37196|-43.58271|2.879|5
2011-01-19T03:11:06.068Z|176.37152|-38.00686|3.61|146.8343
....


finally it works...


hope it helps,
Hamish


-- System Information:
Debian Release: 5.0.7
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.26-2-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages xml2 depends on:
ii  libc6               2.7-18lenny7         GNU C Library: Shared libraries
ii  libxml2             2.6.32.dfsg-5+lenny3 GNOME XML library

xml2 recommends no packages.

xml2 suggests no packages.

-- no debconf information



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to