473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is wrong? The minidom or the XML file?

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
2 10206
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sunil Movva | last post by:
I have an application that uses xml to communicate between threads. One of the threads in my app creates an xml message and sends it to a second thread. This second thread parses the message and...
1
by: Ruslan | last post by:
Hi, everybody. In this excerpt of code enc = 'some_type_of_encoding' def _encode(v): if isinstance(v, UnicodeType): v = v.encode(v) return v
4
by: Derek Basch | last post by:
Hello All, I ran into a problem while dynamically constructing XHTML documents using minidom. If you create a script tag such as: script_node_0 = self.doc.createElement("script")...
0
by: Sullivan WxPyQtKinter | last post by:
Hi, I am now using minidom for my current development. I use cloneNode method in Element object, but it just does not work. The test code is very simple as follows: =========CODE==============...
1
by: Paul Kozik | last post by:
I am trying to write a script that reads an XML file (using the minidom module), makes an edit to a few attributes, then saves it back. If I use minidom.Document() to create the xml file, then...
0
by: Gary | last post by:
Howdy I ran into a difference between Python on Windows XP and Linux Fedora 6. Writing a dom to xml with minidom works on Linux. It gives an error on XP if there is an empty namespace. The...
0
by: sweavo | last post by:
Hi all, (Python 2.5 under cygwin) I'm reading a bunch of XML files and merging them in memory - each file contains a number of packages which are to be merged: for fname in gInfiles: ...
2
by: ashmir.d | last post by:
Hi, I am trying to parse an xml file using the minidom parser. <code> from xml.dom import minidom xmlfilename = "sample.xml" xmldoc = minidom.parse(xmlfilename) </code> The parser is...
2
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, I've a xml svg file and I would like to update it with Python. First, I would like to fetch one dom node with getElementByID. I've one issue about this method. This is my example : ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.