Well, if you're sure that the node is an Element, then you could also do
this:

// assume 'doc' is the containing document
// assume 'node' is the element you want to add the attribute to

Attr att = doc.createAttribute("my_att_name");
att.setValue("my_att_value");
node.appendChild(att);

Are you SURE that this isn't a less elegant solution than:

((Element)node).setAttribute("my_att_name", "my_att_value");

I think the second piece of code is much more to the point.

C



                                                                                
                                                       
                                                                                
                                                       
                                               To:       <[EMAIL PROTECTED]>    
                                            
                      "Stephan                 cc:       (bcc: Constantine 
Georges/Towers Perrin)                                      
                      Reiff-Marganiec"         Subject:  Have Node, need to set 
Attribute                                              
                      <[EMAIL PROTECTED]                                        
                                                        
                      k>                                                        
                                                       
                                                                                
                                                       
                      05/20/2003 09:43                                          
                                                       
                      AM                                                        
                                                       
                      Please respond to                                         
                                                       
                      xerces-j-user                                             
                                                       
                                                                                
                                                       
                                                                                
                                                       




Hi,

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?

Stephan

--
Dr Stephan Reiff-Marganiec
Research Fellow
Department of Computing Science; University of Stirling
email: [EMAIL PROTECTED]    tel: 01786 46 7448

--
The University of Stirling is a university established in Scotland by
charter at Stirling, FK9 4LA.  Privileged/Confidential Information may
be contained in this message.  If you are not the addressee indicated
in this message (or responsible for delivery of the message to such
person), you may not disclose, copy or deliver this message to anyone
and any action taken or omitted to be taken in reliance on it, is
prohibited and may be unlawful.  In such case, you should destroy this
message and kindly notify the sender by reply email.  Please advise
immediately if you or your employer do not consent to Internet email
for messages of this kind.  Opinions, conclusions and other
information in this message that do not relate to the official
business of the University of Stirling shall be understood as neither
given nor endorsed by it.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to