[lxml-dev] Adding internal DTD entities?

Hello all, First, thanks to those responsible for lxml, it has made processing xml in python an almost-fun experience! ;) I have only found one thing I need to be able to do, but of which I can't seem to find any examples. I have entities defined in a file that is shared by all of the files in a document (which are xi:include'ed into the main doc). Thus, I want each document to begin with something like: <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ <!ENTITY % common_entities SYSTEM "common.ent" > %common_entities; ]> The problem is that some of the files in the doc are auto-generated by a python/lxml pre-processing script, and I can't figure out how to have lxml insert that entity definition into the doctype declaration. Any suggestions here would be greatly appreciated. Thanks! --Brad

Brad Smith, 28.04.2010 20:22:
There isn't currently a way to inject an internal DTD subset. Your best bet is to either write out the DTD before the serialised document (easy if you serialise to UTF-8), or to parse a new empty document with the above internal subset and replace its content by your own XML tree, then serialise that. Not exactly the most beautiful solutions, but they usually work well. Stefan

Brad Smith, 28.04.2010 20:22:
There isn't currently a way to inject an internal DTD subset. Your best bet is to either write out the DTD before the serialised document (easy if you serialise to UTF-8), or to parse a new empty document with the above internal subset and replace its content by your own XML tree, then serialise that. Not exactly the most beautiful solutions, but they usually work well. Stefan
participants (2)
-
Brad Smith
-
Stefan Behnel