Python & XML: Ch.5, Problem

Lemniscate d_blade8 at
Wed Oct 30 23:34:21 CET 2002

Hi everybody,

     I'm trying to sit here and learn some Python & XML (from the book
of the same name) and I've run across a problem.  In Python & XML
(Example 5-2), the following code is made available:
import sys

from xml.dom.ext.reader import PyExpat
from xml.xpath          import Evaluate

path0 = "ship/captain"

reader = PyExpat.Reader()
dom = reader.fromStream(sys.stdin)

captain_elements = Evaluate(path0, dom.documentElement)
for element in captain_elements:
    print "Element: ", element

I use it, just the way is supposed to be used (using the ships.xml
file available on the books site).  However, I get the following
Traceback (most recent call last):

  File "C:\DESKTOP\BOOKSS~1\PYTHON~1\c5\", line 13, in ?
    dom = reader.fromStream(sys.stdin)
  File "C:\Python22\lib\site-packages\_xmlplus\dom\ext\reader\",
line 65, in fromStream
    success = self.parser.ParseFile(stream)
xml.parsers.expat.ExpatError: no element found: line 1, column 0

In fact, if I use any of the code from c5 I get the same error.  I am
using Python 2.2, and PyXML 8.1 for Python 2.2, as well as having the
the source code for all the examples from the book's site.  Could
anybody tell me what I am doing wrong?  I looked at the Release Notes
and didn't notice anything.  I would usually just follow the Traceback
to figure out my problem, but, as I said, I am learning and need some
help.  Sorry if this is a simple question.  Thanks.


More information about the Python-list mailing list