# Buggy code
def parse_xml(fname):
    """Returns a parsed xml tree"""

    # handle deprecation warning for XMLParsing a file with DOCTYPE
    class DoctypeSafeCallbackTarget(ElementTree.TreeBuilder):
        def doctype(*args):
            pass

    tree = ElementTree.ElementTree()
    root = tree.parse(
        fname, parser=ElementTree.XMLParser(target=DoctypeSafeCallbackTarget())
    )
    ElementInclude.include(root)
    return tree


# Traceback (ParseError)
...
galaxy.jobs DEBUG 2016-10-24 14:39:57,371 Loading job configuration from ./config/job_conf.xml
galaxy.jobs DEBUG 2016-10-24 14:39:57,372 Read definition for handler 'main'
galaxy.jobs INFO 2016-10-24 14:39:57,373 Setting <handlers> default to child with id 'main'
galaxy.jobs DEBUG 2016-10-24 14:39:57,374 <destinations> default set to child with id or tag 'all.q'
galaxy.jobs DEBUG 2016-10-24 14:39:57,374 Done loading job configuration
beaker.container DEBUG 2016-10-24 14:39:58,124 data file ./database/citations/data/container_file/4/48/48e563f148dc04d8b31c94878c138019862e580d.cache
Traceback (most recent call last):
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/webapps/galaxy/buildapp.py", line 63, in paste_app_factory
app = galaxy.app.UniverseApplication( global_conf=global_conf, **kwargs )
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/app.py", line 93, in __init__
self._configure_toolbox()
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/config.py", line 775, in _configure_toolbox
self.reload_toolbox()
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/config.py", line 761, in reload_toolbox
self.toolbox = tools.ToolBox( tool_configs, self.config.tool_path, self )
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/tools/__init__.py", line 111, in __init__
app=app,
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/tools/toolbox/base.py", line 1051, in __init__
super(BaseGalaxyToolBox, self).__init__(config_filenames, tool_root_dir, app)
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/tools/toolbox/base.py", line 71, in __init__
self._init_integrated_tool_panel( app.config )
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/tools/toolbox/integrated_panel.py", line 36, in _init_integrated_tool_panel
self._load_integrated_tool_panel_keys()
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/tools/toolbox/base.py", line 355, in _load_integrated_tool_panel_keys
tree = parse_xml( self._integrated_tool_panel_config )
File "/mnt/shared/galaxy/galaxy-dist/lib/galaxy/util/__init__.py", line 187, in parse_xml
root = tree.parse( fname, parser=ElementTree.XMLParser( target=DoctypeSafeCallbackTarget() ) )
File "/mnt/shared/galaxy/apps/python/2.7.11/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
File "/mnt/shared/galaxy/apps/python/2.7.11/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/mnt/shared/galaxy/apps/python/2.7.11/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
ParseError: not well-formed (invalid token): line 164, column 40
Removing PID file paster.pid

# Fixed code
def parse_xml(fname):
    """Returns a parsed xml tree"""

    # handle deprecation warning for XMLParsing a file with DOCTYPE
    class DoctypeSafeCallbackTarget(ElementTree.TreeBuilder):
        def doctype(*args):
            pass

    tree = ElementTree.ElementTree()
    try:
        root = tree.parse(
            fname, parser=ElementTree.XMLParser(target=DoctypeSafeCallbackTarget())
        )
    except ParseError:
        log.exception("Error parsing file %s", fname)
        raise
    ElementInclude.include(root)
    return tree