[XML-SIG] DOM handling with parsed element

Thomas B. Passin tpassin@home.com
Thu, 13 Dec 2001 17:31:34 -0500


As I wrote last week, by default one needs the "NS" versions of the DOM
methods, although there seems to be some inconsistency about when that is
required.  In Horst's example, the value of the "test" attribute is
retrieved by using

print "attribute:", e[0].getAttributeNS('',"test")

This prints the value "1" rather than "test" as Horst expected, because "1"
is in fact the value of the "test" attribute.

I still don't know why getElementsByTagName() doesn't have to be
getElementsByTagNameNS() - it's a bug, isn't it?

Presumably in the next release of pyxml, all these NS functions will require
None instead of '' for a missing namespace.

Cheers,

Tom P


[<horst@freedict.de>]

> I modified the dom test program to:
>
> <program>
>
> from xml.dom import Node        # MUST be first
> from xml.dom import implementation, DOMException
> from xml.dom import HIERARCHY_REQUEST_ERR, NOT_FOUND_ERR
> from xml.dom import INDEX_SIZE_ERR, INVALID_CHARACTER_ERR, SYNTAX_ERR
> from xml.dom.ext.reader.Sax2 import FromXml
> from xml.dom.ext import PrettyPrint
>
>
> test_text = """<?xml version="1.0"?>
> <doc>
> <title test="1">This is a test</title>
> <h1>Don't panic</h1>
> <p>Maybe it will work.</p>
> <h2>We can handle it</h2>
> <h3>Yes we can</h3>
> <h3>Or maybe not</h3>
> End of test.
> </doc>
> """
>
> doc = FromXml(test_text)
>
> # Detailed test suite for the DOM
> from xml.dom import Document
> e = doc.getElementsByTagName('title')
> print "e:", e[0]
> print "attribute:", e[0].getAttribute("test")
>
> for attrib in e[0].attributes:
>     print "attrib:", attrib.name
>
>
> </program>
>
>
> the result is however:
>
> > python test_mydom.py
> e: <Element Node at 82de82c: Name='title' with 1 attributes and 1
children>
> attribute:
> attrib: test
>
> Where I expected to retrive: "attribute: test", as the title element has
> the attribute test.
>
> Where are things going wrong?