>I can see that Elements have a setAttribute method. I have a node (Node n)
>and would like to set an attribute. Can I just cast the Node into Element,
>or is there a nicer way?
1) As others have said, don't touch setAttribute unless you really want to
create a Level 1 Only (non-namespace-tolerant) DOM. Use the ...NS() version
of these calls when available.
2) Yes, if the Node is an Element you can cast it to Element and then use
.setAttributeNS. Of course the cast will fail if the node isn't of this
type.
3) It's possible, though less convenient, to avoid casting and operate the
DOM in terms of the low-level Node, NodeList, and NamedNodeMap objects.
((Element)myNode).setAttributeNS(...) is effectively a shorthand for:
myNode.getAttributes().setNamedItemNS(
myNode.getOwnerDocument().createAttributeNS(...));
(Note that the getAttributes() call returns a NamedNodeMap only for Element
nodes; it returns null for others.)
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]