[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
light?
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>
]>
<school>
    <classes>
        <class classid="A1">
            <name>Algebra I</name>
            <description>
                Gentle introduction to Algebra!
            </description>
            <date>4.30.03</date>
            <limit>20</limit>
            <locationRef locationid="L1"/>
            <persons>
                <person personid="P2"/>
                <person personid="P1"/>
            </persons>
        </class>
        <class classid="A2">
            <name>Trigonometry I</name>
            <description>
                Learn the science of angles.
            </description>
            <date>4.29.03</date>
            <limit>18</limit>
            <locationRef locationid="L2"/>
            <persons></persons>
        </class>
    </classes>
        <locations>
            <location locationid="L1">
                <name>Lecture Hall I</name>
                <room>25</room>
                <status>Open</status>
            </location>
            <location locationid="L2">
                <name>Lecture Hall II</name>
                <room>3</room>
                <status>Open</status>
            </location>            
        </locations>
</school>


Thanks,
Levy Lazarre
Winter Haven Hospital
llazarre@yahoo.com




__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com