473,388 Members | 1,426 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,388 software developers and data experts.

ElementTree and DTDs

Hello,

Is ElementTree supposed to load DTDs? I have some xmls heavy on
entities and it fails this way:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>filename = "revo/xml/a.xml"
import xml.etree.ElementTree as ET
ET.parse(filename)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 862, in
parse
tree.parse(source, parser)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 586, in
parse
parser.feed(data)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1245, in
feed
self._parser.Parse(data, 0)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1201, in
_default
self._parser.ErrorColumnNumber)
xml.parsers.expat.ExpatError: undefined entity &jcirc;: line 13,
column 10
>>import xml.etree.cElementTree as ET
ET.parse(filename)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 45, in parse
File "<string>", line 32, in parse
SyntaxError: undefined entity &c_j;: line 46, column 17

Thanks.
Jun 27 '08 #1
2 3615
Or is there another library that would handle DTDs correctly,
performing entity replacements?

Thanks.

On May 16, 12:20*am, J. Pablo Fernández <pup...@pupeno.comwrote:
Hello,

Is ElementTree supposed to load DTDs? I have some xmls heavy on
entities and it fails this way:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>filename = "revo/xml/a.xml"
>import xml.etree.ElementTree as ET
ET.parse(filename)

Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
* File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 862, in
parse
* * tree.parse(source, parser)
* File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 586, in
parse
* * parser.feed(data)
* File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1245, in
feed
* * self._parser.Parse(data, 0)
* File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1201, in
_default
* * self._parser.ErrorColumnNumber)
xml.parsers.expat.ExpatError: undefined entity &jcirc;: line 13,
column 10>>import xml.etree.cElementTree as ET
>ET.parse(filename)

Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
* File "<string>", line 45, in parse
* File "<string>", line 32, in parse
SyntaxError: undefined entity &c_j;: line 46, column 17

Thanks.
Jun 27 '08 #2
J. Pablo Fernández wrote:
Is ElementTree supposed to load DTDs?
AFAIR, you have to provide entities by hand.

Or is there another library that would handle DTDs correctly,
performing entity replacements?
http://codespeak.net/lxml
http://codespeak.net/lxml/parsing.html#parser-options

Stefan
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stewart Midwinter | last post by:
I want to parse a file with ElementTree. My file has the following format: <!-- file population.xml --> <?xml version='1.0' encoding='utf-8'?> <population> <person><name="joe" sex="male"...
1
by: Greg Wilson | last post by:
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: ...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
15
by: Steven Bethard | last post by:
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with...
0
by: Greg Aumann | last post by:
I am trying to write some python code for a library that reads an XML-like language from a file into elementtree data structures. Then I want to be able to read and/or modify the structure and then...
2
by: mirandacascade | last post by:
Situation is this: 1) I have inherited some python code that accepts a string object, the contents of which is an XML document, and produces a data structure that represents some of the content of...
5
by: saif.shakeel | last post by:
#!/usr/bin/env python from elementtree import ElementTree as Element tree = et.parse("testxml.xml") for t in tree.getiterator("SERVICEPARAMETER"): if t.get("Semantics") == "localId":...
1
by: Mike Slinn | last post by:
The following short Python program parses a KML file and displays the names of all Marks and Routes: from elementtree.ElementTree import ElementTree tree = ElementTree(file='test.kml') kml =...
3
by: gray.bowman | last post by:
I'm messing around with trying to write an xml file using xml.etree.ElementTree. All the examples on the internet show the use of ElementTree.write(), although when I try to use it it's not...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.