W3C home > Mailing lists > Public > html-tidy@w3.org > October to December 2000

Re: modifying attributes with JTidy

From: Gary L Peskin <garyp@firstech.com>
Date: Wed, 29 Nov 2000 06:36:08 -0800
Message-ID: <3A251458.12BFBF86@firstech.com>
To: Austin Rosenfeld <arosenfeld@agentware.net>, Html-Tidy <html-tidy@w3.org>
Austin Rosenfeld wrote:
> 
>  I am trying to use the JTidy libraries to modify a DOM tree, and
>  am not having much success.  I need to take attributes out of a node, but
> the
>  methods in org.w3c.tidy.DOMAttrImpl to do this are all stubbed out (and
> return null).
>  Here's the code I have been using:
>         //some desired transformations:
>       //<A VLINK="xxx">  --> <A>
>         //<HR NOSHADE> --> <HR>
>         NamedNodeMap    attributes  = node.getAttributes();
>         Node            toRemove    = null;
>         toRemove = attributes.getNamedItem( mAttribute.toUpperCase() );
>              if ( toRemove != null )
>              {
>                  toRemove.setNodeValue( "" ); //works, but I get
>                          //'element=""', where I want absolutely nothing
>                  attributes.removeNamedItem( mAttribute.toUpperCase() );
>                          //has no effect at all, regardless of what case I
> change mAttribute to
>              }

Austin --

The methods you are using are not implemented in the JTidy DOM support. 
Try

  ((Element) node).removeAttributeNode( toRemove );

-or-

You can eliminate the getNamedItem call altogether and do

  ((Element) node).removeAttribute( mAttribute.toUpperCase() );

Please let us know if these work for you.

Gary
Received on Wednesday, 29 November 2000 09:35:47 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 3 April 2012 06:13:44 GMT