Python & XML & DTD (warning: noob attack!)

Igor Fedorow igor.NOSPAM at
Thu Jan 29 13:04:44 CET 2004

Hello all,

I have an XML file with an internal DTD which looks roughly like this:

	<?xml version="1.0"?>
	<!DOCTYPE root [
	  <!ELEMENT  root         (node)*>
	  <!ELEMENT  node         (description, info, node*)>
	  <!ELEMENT  description  (#PCDATA)>
	  <!ELEMENT  info         EMPTY>
	  <!ATTLIST  info
	    text     CDATA        #REQUIRED
	    <description>node 1</description>	
	    <info text="info 1" />
	      <description>node 1-1</description>
	      <info text="info 1-1" />
	    <description>node 2</description>
	    <info text="info 2" />
	      <description>node 2-1</description>
	      <info text="info 2-1" />
	      <description>node 2-2</description>
	      <info text="info 2-2" />

I want to parse this file into my application, modify the data (this includes
maybe creating and/or deleting nodes), and write it back into the file --
including the DTD. (It doesn't necessarily need validation, though.)

I tried xml.dom.ext.PrettyPrint, but it produces only

	<?xml version='1.0' encoding='UTF-8'?>
	<!DOCTYPE root>

actually lacking the document type definition.

Any help is appreciated!

Thanks in advance & cheers =)

More information about the Python-list mailing list