473,698 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:&Descri ption;
</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\co des\xmltest.py" , line 4, in
-toplevel-
xmldoc = minidom.parse(' samplexml.xml')
File "C:\Python23\li b\xml\dom\minid om.py", line
1919, in parse
return expatbuilder.pa rse(file)
File "C:\Python23\li b\xml\dom\expat builder.py", line
924, in parse
result = builder.parseFi le(fp)
File "C:\Python23\li b\xml\dom\expat builder.py", line
207, in parseFile
parser.Parse(bu ffer, 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 10277
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******* *************** *************** *@python.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:&Descri ption;
</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\co des\xmltest.py" , line 4, in
-toplevel-
xmldoc = minidom.parse(' samplexml.xml')
File "C:\Python23\li b\xml\dom\minid om.py", line
1919, in parse
return expatbuilder.pa rse(file)
File "C:\Python23\li b\xml\dom\expat builder.py", line
924, in parse
result = builder.parseFi le(fp)
File "C:\Python23\li b\xml\dom\expat builder.py", line
207, in parseFile
parser.Parse(bu ffer, 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
2172
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 creates a new xml message copying most part of the first message and sends it to a third thread. The second thread was able to parse the message, while the third thread is not able to parse the message that it received. I am using minidom...
1
4906
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
2868
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") script_node_0.setAttribute("type", "text/javascript") script_node_0.setAttribute("src", "../test.js") minidom renders it as:
0
1907
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============== from xml.dom.minidom import * a=Element('see') print a.toprettyxml() b=a.cloneNode(True)
1
10075
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 write it with toprettyprint, it looks fine. However, if I use xml.minidom.parse to parse the xml document, change a few attributes with setAttribute, then write back with toprettyxml, my XML file gets loaded up with spaces between many of the...
0
1513
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 problem was handled in CVS a while ago. http://mail.python.org/pipermail/xml-sig/2003-October/009904.html
0
1424
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: doc=xml.dom.minidom.parse(fname) if gDoc is None:
2
12584
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 failing on this line:
2
4967
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 : My SVG file :
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.