<p>Is there a way, when I parse an XML document using lxml, to validate that document against its DTD using an external catalog file?   I need to be able to work the fixed attributes defined in a document’s DTD.</p>

[{'answer_id': 13040, 'author': 'Michael Twomey', 'author_id': 995, 'author_profile': 'https://Stackoverflow.com/users/995', 'pm_score': 1, 'selected': False, 'text': '<p>Can you give an example? According to the <a href="http://codespeak.net/lxml/validation.html" rel="nofollow noreferrer">lxml validation docs</a>, lxml can handle DTD validation (specified in the XML doc or externally in code) and system catalogs, which covers most cases I can think of.</p>\n\n<pre><code>f = StringIO("&lt;!ELEMENT b EMPTY&gt;")\ndtd = etree.DTD(f)\ndtd = etree.DTD(external_id = "-//OASIS//DTD DocBook XML V4.2//EN")\n</code></pre>\n'}, {'answer_id': 36219, 'author': 'gz.', 'author_id': 3665, 'author_profile': 'https://Stackoverflow.com/users/3665', 'pm_score': 0, 'selected': False, 'text': '<p>It seems that lxml does not expose this libxml2 feature, grepping the source only turns up some #defines for the error handling:</p>\n\n<pre><code>C:\\Dev&gt;grep -ir --include=*.px[id] catalog lxml-2.1.1/src | sed -r "s/\\s+/ /g"\nlxml-2.1.1/src/lxml/dtd.pxi: catalog.\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_FROM_CATALOG = 20 # The Catalog module\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_WAR_CATALOG_PI = 93 # 93\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_MISSING_ATTR = 1650\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_ENTRY_BROKEN = 1651 # 1651\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_PREFER_VALUE = 1652 # 1652\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_NOT_CATALOG = 1653 # 1653\nlxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_RECURSION = 1654 # 1654\nlxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG=20\nlxml-2.1.1/src/lxml/xmlerror.pxi:WAR_CATALOG_PI=93\nlxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_MISSING_ATTR=1650\nlxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_ENTRY_BROKEN=1651\nlxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_PREFER_VALUE=1652\nlxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_NOT_CATALOG=1653\nlxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_RECURSION=1654\n</code></pre>\n\n<p>From the <a href="http://xmlsoft.org/catalog.html" rel="nofollow noreferrer">catalog implementation in libxml2 page</a> it seems possible that the \'transparent\' handling through installation in /etc/xml/catalog may still work in lxml, but if you need more than that you can always abandon lxml and use the default python bindings, which do expose the catalog functions.</p>\n'}, {'answer_id': 8391738, 'author': 'Brecht Machiels', 'author_id': 438249, 'author_profile': 'https://Stackoverflow.com/users/438249', 'pm_score': 3, 'selected': False, 'text': '<p>You can add the catalog to the <code>XML_CATALOG_FILES</code> environment variable:</p>\n\n<pre><code>os.environ[\'XML_CATALOG_FILES\'] = \'file:///to/my/catalog.xml\'\n</code></pre>\n\n<p>See <a href="http://thread.gmane.org/gmane.comp.python.lxml.devel/5907" rel="noreferrer">this thread</a>. Note that entries in <code>XML_CATALOG_FILES</code> are space-separated URLs. You can use Python\'s <code>pathname2url</code> and <code>urljoin</code> (with <code>file:</code>) to generate the URL from a pathname.</p>\n'}]
['https://Stackoverflow.com/questions/12591', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/207/']