- From: Fred L. Drake, Jr. <fdrake@acm.org>
- Date: Mon, 21 May 2001 09:58:58 -0400 (EDT)
- To: "Joseph Kesselman" <keshlam@us.ibm.com>
- Cc: W3C DOM mailing list <www-dom@w3.org>
Joseph Kesselman writes: > The nodeName (together with the namespace URI) indicates the semantic role > this node is playing in the document, and different names even of the same > node type may reflect different subclassing of the node. Look at the HTML > DOM for plenty of examples; some Element nodes carry methods that others > may not. Other DOMs may implement similar role-specific extensions. Since > you can't change an object's class once it has been created (in most > languages), we really can't promise that you can change the semantic role > after the object has been created -- and hence both nodeName and > namespaceURI are immutable. I understand the intention here, but being able to change either the tagName or the namespaceURI (or both) can be incredibly useful for all kinds of data conversions. This is especially useful if some of the operations needed just don't make sense in XSLT, so you're working from a programming language anyway. My primary example for this is a document conversion project in which I'm converting LaTeX documents in XML -- the paragraph marking is done very differently in LaTeX (no tags), and while XSLT *may* be able to do the right thing, I'm firmly convinced it would take me a year to figure it out (since I'm not an XSLT guru). So for the tagName changes I need to make, it's by far easiest to just change the name. I can use implementation-specific extensions to do so, but I've already had to change implementations once (and make changes all over my code to support the new way of changing tagName). I'd love to see a standard way to do it, and could accept that some DOMs will have to raise an exception (NO_MODIFICATION_ALLOWED would suffice). > >If you're passing a node to a subroutine to have it filled > > If you need to set the node's name/type: Don't. Instead, pass the Document > node into the subroutine, and have the subroutine use the Document's > factory methods create and return a new Node object of the appropriate type > and with the appropriate name. This only works in the case of creating new nodes; it can be very expensive to create a new node, migrate children & attribute nodes of the original, and the replace the original with the new node. It also makes the code more difficult to read and maintain. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs at Digital Creations
Received on Monday, 21 May 2001 10:00:08 UTC