diff --git a/idassigner.py b/idassigner.py index 77400c2..8d7f4ca 100644 --- a/idassigner.py +++ b/idassigner.py @@ -11,6 +11,7 @@ import argparse import logging +import sys from datetime import datetime from lxml import etree from copy import deepcopy @@ -24,7 +25,11 @@ def assign_ids(chapter_tree): """Assign xml:ids to various elements""" - chapter_id = (chapter_tree.attrib["{http://www.w3.org/XML/1998/namespace}id"]) + try: + chapter_id = (chapter_tree.attrib["{http://www.w3.org/XML/1998/namespace}id"]) + except KeyError: + logging.error("Chapter has no id. Exiting") + sys.exit() logging.debug("The id of this chapter is %s", chapter_id) footnotes = chapter_tree.xpath("//t:note[@place='bottom']", namespaces=NS_MAP)