On Wed, 27 Apr 2005 14:29:37 +0200, Martijn Faassen wrote:
I haven't looked into DTDs at all yet in the context of lxml, I'm afraid. ... Still, the libxml2 API is huge, not extensively documented, and fairly intimidating, so to figure this out would still be a bit of a task. I myself lack the time to work on it (unless I got paid to do it of course :), and DTD support is not currently high on my agenda, but if you want to discuss this and work towards patches (and tests) to support this, I'd be happy to give you lots of assistance.
I recently had the same problem, wanting to validate against DTDs specified in the XML files. I came up with the following libxml2 code, which takes a string parameter and appears to work fine: import libxml2 def _getValidationErrors(payload): errors = [] def store_error(ctx, str): errors.append(str) libxml2.registerErrorHandler(store_error, None) ctx = libxml2.createMemoryParserCtxt(payload, len(payload)) ctx.validate(1) ctx.parseDocument() ctx.doc().freeDoc() if ctx.isValid(): return None else: return "\n".join(errors) I don't have time to work out where/how best to integrate this into lxml, so I just thought I'd post the code here in case it helps somebody else either to do that integration or just to validate their files. Thanks, Malcolm. -- [] j a m k i t web solutions for charities malcolm cleaton T: 020 7549 0520 F: 020 7490 1152 M: 07986 563852 W: www.jamkit.com