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

Igor Fedorow igor.NOSPAM at obda.net
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
	  >
	]>
	<root>
	  <node>
	    <description>node 1</description>	
	    <info text="info 1" />
	    <node>
	      <description>node 1-1</description>
	      <info text="info 1-1" />
	    </node>
	  </node>
	  <node>
	    <description>node 2</description>
	    <info text="info 2" />
	    <node>
	      <description>node 2-1</description>
	      <info text="info 2-1" />
	    </node>
	    <node>
	      <description>node 2-2</description>
	      <info text="info 2-2" />
	    </node>
	  </node>
	</root>

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>
	<root>
	   ...
	</root>

actually lacking the document type definition.

Any help is appreciated!

Thanks in advance & cheers =)
*igor*



More information about the Python-list mailing list