Skip to content

Instantly share code, notes, and snippets.

@leavesofgrass
Created February 5, 2013 02:31
Show Gist options
  • Save leavesofgrass/4711648 to your computer and use it in GitHub Desktop.
Save leavesofgrass/4711648 to your computer and use it in GitHub Desktop.
Validate XML with DTD using Python (lxml)
from lxml import etree
InXML = open('file.xml', 'r');
DefFile = open('def.dtd', 'r');
PostParse = etree.XML(InXML.read())
dtd = etree.DTD(DefFile)
print(dtd.validate(PostParse))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment