Menu

removing all Style, class and IDs from html

Anonymous
2012-09-19
2014-03-17
  • Anonymous

    Anonymous - 2012-09-19

    Hello,

    I'm trying to use htmlcleaner to remove all css from code, Ids and classes too.
    There is a proper way to apply a transformation like like this weird, wrong code?

    tt = new TagTransformation("*","*",true);
    tt.addAttributeTransformation("style","");
    tt.addAttributeTransformation("id","");
    tt.addAttributeTransformation("class","");
    

    Thanks in advance;
    Marcelo,
    Brazil

     
  • Willi Firulais

    Willi Firulais - 2014-03-14

    Hallo,

    This is an old entry, but has someone found a solution for this?
    The Wildcard "*" seems not to work in the current Version.

    Thx a lot for any hint on this,
    Willi

     
  • Scott Wilson

    Scott Wilson - 2014-03-17

    You can use global transformations for this. Here is an example from the test suite that removes any attributes starting with "on" such as "onmouseover":

    :::Java
    
            CleanerTransformations transformations = new CleanerTransformations();
            AttributeTransformationPatternImpl attPattern = new AttributeTransformationPatternImpl(Pattern.compile("^\\s*on", Pattern.CASE_INSENSITIVE), null, null);
            transformations.addGlobalTransformation(attPattern);
    
            CleanerProperties props = cleaner.getProperties();
            props.setCleanerTransformations(transformations);
    
     

Log in to post a comment.

MongoDB Logo MongoDB