#!/bin/bash
# WF 2020-07-17
# get proceedings xml nodes from dblp xml download

# if you do not have xq you might wan to install it with
# pip install yq
# see https://pypi.org/project/yq/

# use dblpconf compatible location
xml=$HOME/.dblp/dblp.xml
tmpxml=/tmp/proceedings-dblp.xml
json=sampledata/dblp.json
echo "starting to extract $json from $xml ..."
date
echo "extracting proceedings nodes from $xml"
# copy the xml header
head -3 $xml > $tmpxml
# make sure there are newlines before and after end tags
# of type proceeding with sed and then filter with awk
# https://stackoverflow.com/a/24707372/1497139
cat $xml | sed $'s/<proceedings/\\\n&/g' | sed $'s/<.proceedings>/&\\\n/g' | awk '
# select proceedings nodes (which should be clearly separated by now)
/<proceedings/,/<\/proceedings>/ {
  print
}' >> $tmpxml
echo "</dblp>" >> $tmpxml
echo "converting xml format to $json"
xq . $tmpxml > $json
echo "finished"
date
