[XML-SIG] Proper way of generating a parentless Node object
Mark Humphrey
msph@alyra.org
Tue, 18 Jun 2002 13:32:47 -0500
Okay, this is a kind of odd situation, but I need to know the correct way to create a Node (Text node or Element, I actually have to create both) that is not attached to a particular document and that can be inserted into any given document.
The situation is this. I am using a namespace in a document so that I can embed cross-references in the document. I want to be able to use the same cross-references in several document types. With this in mind, I've also created a Python class that can read those cross-references and then export them again in several different formats, including XHtml.
The problem, though, is that this cross-reference class does not know what the parent document will be.
Normally, when I need to create a node, I use code that looks like this:
from xml.dom import DOMImplementation
def toHtml (self):
dom = DOMImplementation.DOMImplementation()
doc = dom.createDocument(None, u'Target', None)
target = doc.createElement(u'a')
If I do this, though, I can't attach "target" to anything other than the document named "Target". So, I was thinking of doing this:
from xml.dom import Node
def toHtml (self):
target = Node()
target.nodeName = u'a'
target.nodeType = Node.ELEMENT_NODE
return target
But that has me accessing not only internal object variables, it has me *setting* variables that the DOM spec says are supposed to be read-only.
How should I really be doing this? Essentially, I'm trying to make an element that I can attach to any document.
--
Mark "Markus" Humphrey <msph@alyra.org>
http://www.alyra.org/~msph/
This email has a digital signature. If you can't verify the signature, you
can't prove it's from me. Learn about encryption on my web site.