[Tutor] getElementById() in XML 4DOM implementation

Levy Lazarre llazarre@yahoo.com
Wed Apr 30 11:18:01 2003

Hi all,

I am having some difficulties with the
getElementById() method processing an XML file. It
seems to work fine in the minidom implementation, but
not the 4DOM implementation. Could somebody shed some
Here is some testing:

>>> from xml.dom import minidom
>>> xmldoc = minidom.parse('school.xml')
>>> xmldoc.getElementById("L2")
<DOM Element: location at 0x1198a50>

But the same code doesn't seem to work with the 4DOM
implementation, where the method is also provided:

>>> from xml.dom.ext.reader import Sax2
>>> reader = Sax2.Reader()
>>> doc = reader.fromStream(file('school.xml'))
>>> doc.getElementById("L2")

The test file('school.xml') is like:

<?xml version="1.0"?>
<!DOCTYPE school [
     <!ATTLIST location locationid ID #REQUIRED>
        <class classid="A1">
            <name>Algebra I</name>
                Gentle introduction to Algebra!
            <locationRef locationid="L1"/>
                <person personid="P2"/>
                <person personid="P1"/>
        <class classid="A2">
            <name>Trigonometry I</name>
                Learn the science of angles.
            <locationRef locationid="L2"/>
            <location locationid="L1">
                <name>Lecture Hall I</name>
            <location locationid="L2">
                <name>Lecture Hall II</name>

Levy Lazarre
Winter Haven Hospital

Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.