zoukankan      html  css  js  c++  java
  • nekohtml转换html时标签变大写的问题

    public static Document transferByNeko(InputStream stream, String charset)
        {
            if (stream == null)
                return null;
            
            if(StringUtils.isEmpty(charset)){
                charset = DEFAULT_CHARSET;
            }
    
    
            //NEKOHTML的DOMParser会将html标签转化成大写,是否设置下面的配置都没有意义,解决办法是需要使用xerces的DOMParser
    //        DOMParser domParser = new DOMParser();
    //        Document doc = null;
    //        ByteArrayOutputStream byteOs = null;
    //        Writer writer = null;
    //        InputSource inputSource = null;
    //        DocumentType documentType = null;
    //        org.w3c.dom.Document document = null;
    //        DOMReader domReader = null;
    //        try {
    //            domParser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
    //            domParser.setProperty("http://cyberneko.org/html/properties/names/attrs", "lower");
    //            domParser.setProperty("http://cyberneko.org/html/properties/default-encoding", "UTF-8");
    //
    //            domParser.setFeature("http://xml.org/sax/features/namespaces", false);
    //            domParser.setFeature("http://cyberneko.org/html/features/balance-tags", true);
    //            domParser.setFeature("http://cyberneko.org/html/features/scanner/script/strip-comment-delims", false);
    //
    //            byteOs = new ByteArrayOutputStream();
    //            writer = new Writer(byteOs, charset);
    //            XMLDocumentFilter domFilter[] = {
    //                writer
    //            };
    //            domParser.setProperty("http://cyberneko.org/html/properties/filters", domFilter);
    //            inputSource = new InputSource(new InputStreamReader(stream, Charset.forName(charset)));
    //            domParser.parse(inputSource);
    //            document = domParser.getDocument();
    //            documentType = document.getDoctype();
    //            if (documentType != null)
    //                document.removeChild(documentType);
    //            domReader = new DOMReader();
    //            doc = domReader.read(document);
    //        } catch (SAXNotRecognizedException e) {
    //            e.printStackTrace();
    //        } catch (SAXNotSupportedException e) {
    //            e.printStackTrace();
    //        } catch (UnsupportedEncodingException e) {
    //            e.printStackTrace();
    //        } catch (SAXException e) {
    //            e.printStackTrace();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }finally{
    //            IOUtils.closeQuietly(byteOs);
    //            IOUtils.closeQuietly(stream);
    //        }
    
            //采用xerces的DOMParser
            Document doc = null;
            DocumentType documentType = null;
            org.w3c.dom.Document document = null;
            DOMReader domReader = null;
            ByteArrayOutputStream byteOs = null;
            Writer writer = null;
            InputSource inputSource = null;
            try {
                HTMLConfiguration htmlConfiguration = new HTMLConfiguration();
                htmlConfiguration.setProperty("http://cyberneko.org/html/properties/names/elems","lower");
                org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(htmlConfiguration);
                inputSource = new InputSource(new InputStreamReader(stream, Charset.forName(charset)));
                parser.parse(inputSource);
                document = parser.getDocument();
                documentType = document.getDoctype();
                if (documentType != null)
                    document.removeChild(documentType);
                domReader = new DOMReader();
                doc = domReader.read(document);
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return doc;
        }
        
  • 相关阅读:
    github not authorized eclipse 关于 代码不能提交到GitHub
    idea 导入项目后 有的项目目录结构不展开解决办法
    intellij idea 主题大全,看不惯idea 那2种主题的来这里了
    win10 系统输入法与 idea的 ctr+shift+f 快捷键冲突,解决办法
    此地址使用了一个通常用于网络浏览以外目的的端口。出于安全原因,Firefox 取消了该请求。
    关于IntelliJ IDEA有时候快捷键无效的说明
    杜恩德是谁?
    oracle如何连接别人的数据库,需要在本地添加一些配置
    2.6---找有环链表的开头结点(CC150)
    2.3---删除链表的结点,不提供头结点(CC150)
  • 原文地址:https://www.cnblogs.com/yesun/p/8628285.html
Copyright © 2011-2022 走看看