What is wrong? The minidom or the XML file?

Anthony Liu antonyliu2002 at yahoo.com
Wed Mar 10 04:14:19 EST 2004


I copy-pasted the following sample xml document from
http://slis-two.lis.fsu.edu/~xml/sample.html and saved
it as samplexml.xml.  Please note that I removed the
following line

<!DOCTYPE DOCUMENT SYSTEM "simple.dtd">

from the original xml sample.

<?XML version="1.0" encoding="UTF-8"?>
<DOCUMENT trackNum="1234">
<TITLE> Sample Document </TITLE>
<AUTHOR> <FIRSTNAME> Brandon </FIRSTNAME>
<LASTNAME> Voss </LASTNAME>
<COMPANY> The XML Pages </COMPANY> </AUTHOR>
<SUMMARY> This is element text and an entity
follows:&Description;
</SUMMARY>
</DOCUMENT>

Then, I attempted to parse this xml document with the
following python code, which is saved as xmltest.py.

from xml.dom import minidom
xmldoc = minidom.parse('sample.xml')
print xmldoc.toxml()

I got the following error message:

>>> 

Traceback (most recent call last):
  File "C:\Python23\codes\xmltest.py", line 4, in
-toplevel-
    xmldoc = minidom.parse('samplexml.xml')
  File "C:\Python23\lib\xml\dom\minidom.py", line
1919, in parse
    return expatbuilder.parse(file)
  File "C:\Python23\lib\xml\dom\expatbuilder.py", line
924, in parse
    result = builder.parseFile(fp)
  File "C:\Python23\lib\xml\dom\expatbuilder.py", line
207, in parseFile
    parser.Parse(buffer, 0)
ExpatError: not well-formed (invalid token): line 1,
column 5
>>> 

I have no clue why that xml document is not
well-formed.

Any hint please?


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com




More information about the Python-list mailing list