[XML-SIG] DOM handling with parsed element
horst@freedict.de
horst@freedict.de
Thu, 13 Dec 2001 19:12:54 +0100 (CET)
I asked this before, but I did not receive any answer, so I am asking it
again, in a different way. I would appreciate answers VERY much.
I am running linux, and reinstalled Python 2.0.1 and PyXML0.6.6
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?
Thanks for your answers
Horst
--
Horst@freedict.de
Horst Eyermann
Germany
You need a dictionary? - visit http://www.freedict.de
for free (GPL) dictionaries (unix; windows work in progress)
For windows, visit http://www.freedict.de/wbuch
A article (in German) about dictionary efforts on the net
http://www.heise.de/tp/deutsch/inhalt/on/5927/1.html