I'm trying to convert from minidom to ElementTree for handling XML,
and am having trouble with entities in DTDs. My Python script looks
like this:
----------------------------------------------------------------------
#!/usr/bin/env python
import sys, os
from elementtree import ElementTree
for filename in sys.argv[1:]:
ElementTree.par se(filename)
----------------------------------------------------------------------
My first attempt was this XML file:
----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE lec [
<!ENTITY ldots "舰">
]>
<lec title="Introduc tion">
<topic title="Motivati on" summary="motiva tion for course">
<slide>
<b1>Write an introduction&ld ots;</b1>
</slide>
</topic>
</lec>
----------------------------------------------------------------------
Running "python validate.py first.xml" produces:
----------------------------------------------------------------------
Traceback (most recent call last):
File "validate.p y", line 7, in ?
ElementTree.par se(filename)
File "C:\Python23\Li b\site-packages\elemen ttree\ElementTr ee.py",
line 865, in parse
tree.parse(sour ce, parser)
File "C:\Python23\Li b\site-packages\elemen ttree\ElementTr ee.py",
line 589, in parse
parser.feed(dat a)
File "C:\Python23\Li b\site-packages\elemen ttree\ElementTr ee.py",
line 1160, in feed
self._parser.Pa rse(data, 0)
File "C:\Python23\Li b\site-packages\elemen ttree\ElementTr ee.py",
line 1113, in _default
raise expat.error(
xml.parsers.exp at.ExpatError: undefined entity &ldots;: line 9, column
27
----------------------------------------------------------------------
All right, pull the DTD out, and use this XML file:
----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE lec SYSTEM "swc.dtd">
<lec title="Introduc tion">
<topic title="Motivati on" summary="motiva tion for course">
<slide>
<b1>Write an introduction&ld ots;</b1>
</slide>
</topic>
</lec>
----------------------------------------------------------------------
with this minimalist DTD (saved as "swc.dtd" in the same directory as
both the XML file and the script):
----------------------------------------------------------------------
<!ENTITY ldots "舰">
----------------------------------------------------------------------
Same error; only the line number changed. Anyone know what I'm doing
wrong? (Note: minidom loads it just fine...)
Thanks,
Greg Wilson
gv******@cs.uto ronto.ca