By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

What is wrong? The minidom or the XML file?

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Anthony Liu wrote:
<?XML version="1.0" encoding="UTF-8"?> ^
... ExpatError: not well-formed (invalid token): line 1,
column 5


Line 1 column 5 is the L in <?XML. That XML document type declaration
is invalid; the "XML" needs to be in lowercase.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ It's like being on a diving board that you know is too high.
-- Sade Adu
Jul 18 '05 #2

P: n/a
Anthony Liu <an***********@yahoo.com> wrote in message news:<ma**************************************@pyt hon.org>...
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


One additional possibility to get another quick help about errors
in the xml-document is - when working under MS-Windows - to open
the document with the Internet Explorer up from version 5.xx
or so.
In your case it tells me exactly what Erik Max Francis told you.

Regards
Peter
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.