#!/usr/bin/env python
#

import libxml2
import sys

removals = {}

for line in sys.stdin.readlines ():
	line = line.strip ()
	removals[line] = False

doc = libxml2.parseFile (sys.argv[1])
locations = doc.xpathEval ("//location")

for location in locations:
	code = location.xpathEval ("./code")[0].content
	name = location.xpathEval ("./_name")[0].content

	if removals.has_key (code):
		removals[code] = True
		print >> sys.stderr, "Removing", code, name
		if location.prev.name == "text":
			location.prev.unlinkNode ()
		location.unlinkNode ()

for code in removals.keys ():
	if not removals[code]:
		print >> sys.stderr, "!! Code %s not in locations DB" % code

print doc.serialize ('utf-8', 1)
