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;
}
nekohtml转换html时标签变大写的问题的更多相关文章
- Android学习之Button按钮在程序运行时全部变大写的处理
问题: 在layout布局文件中,我们命名的按钮名称是“button1”,程序运行过后,在app上显示出来的是“BUTTON1”,先看源代码和效果: 按钮源代码: 运行效果: 解决办法: 方法一: 在 ...
- 三:C#对象转换Json时的一些高级(特殊)设置;
导航目录: Newtonsoft.Json 概述 一:Newtonsoft.Json 支持序列化与反序列化的.net 对象类型: 二:C#对象.集合.DataTable与Json内容互转示例: ...
- PHP 将秒数转换成时分秒
将秒数转换成时分秒,PHP提供了一个函数gmstrftime,不过该函数仅限于24小时内的秒数转换.对于超过24小时的秒数,我们应该怎么让其显示出来呢,例如 34:02:02 $seconds = 3 ...
- ytu 1938:首字母变大写(水题)
首字母变大写 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 110 Solved: 43[Submit][Status][Web Board] Desc ...
- PowerDesigner中转换物理模型时的命名转换
原文:PowerDesigner中转换物理模型时的命名转换 最近在使用PowerDesigner建模数据库,在使用中积累了一些遇到的问题和解决办法,记录下来,希望对遇到同样问题的朋友有所帮助. 早 期 ...
- HDOJ2026首字母变大写
首字母变大写 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- html标签data大写获取不到值:只能小写+横杠命名
html标签data大写获取不到值:只能小写+横杠命名 例如: <i class="glyphicon glyphicon-question-sign" data-tip-t ...
- <!--转换office时需要此配置 --> <identity impersonate="true" />
1.需要对Office 进行操作时 ,添加权限 <!--转换office时需要此配置 --> <identity impersonate="true" /> ...
- java把html标签字符转普通字符(反转换成html标签)(摘抄)
下面是java把html标签字符转换,我用了spring 包中的 org.springframework.web.util.HtmlUtils 了解了源代码并且进步了使用,发现写得真不错...同时也可 ...
随机推荐
- 判断 Selite中标存在或者字段存在的方法
判断表存在的方法很简单,网上很多: SELECT COUNT(*) FROM sqlite_master where type='table' and name='%s'" % tname; ...
- es6数组去重复
var arr=[1,1,2,3,5,7,7,7] arr=Array.from(new Set(arr))
- MySQL 的instr函数
1.测试数据库: MYSQL数据库 INSTR(STR,SUBSTR) 在一个字符串(STR)中搜索指定的字符(SUBSTR),返回发现指定的字符的位置(INDEX); STR 被搜索的字符串 SUB ...
- [Eclipse插件] 安装和使用JD-Eclipse插件
JD-Core 是一个免费的库,从一个或多个“.class”文件中 重构Java源代码.JD-Core可以用来恢复丢失的源代码,并深究Java运行时类库.支持Java 5的功能:如注释,泛型或键入“枚 ...
- 如何解决weblogic server启动中在IIOP后运行缓慢
WebLogic Server在Linux环境中,有时因为linux OS的安全包没有安装,导致weblogic server 在启动的时候会在长时间的停留在 <2/07/2009 08:54: ...
- rsync运行时出现skipping non-regular file
如果执行 rsync 时提示 skipping non-regular file……,检查下原文件夹中是否包含软链接 修改下脚本文件: rsync -va ... -a == -rlptgoD (no ...
- 二十四种设计模式:桥接模式(Bridge Pattern)
桥接模式(Bridge Pattern) 介绍将抽象部分与它的实现部分分离,使它们都可以独立地变化. 示例有一个Message实体类,对它的操作有Insert()和Get()方法,现在使这些操作的抽象 ...
- Delphi 对象模型学习笔记(转)
摘要 Borland Object Pascal 对象模型(现在已经正是命名为 Delphi 语言)与其他 OOP 语言一样,都提供了一些基础服务: 如对象创建服务.对象释放服务.对象识别服务 ...
- js正则表达式之中文验证(转)
原文地址:http://houfeng0923.iteye.com/blog/1035321 今天做表单提交的输入框条件验证,验证是否包含中文:网上搜了一圈基于js正则表达式的验证基本不好用,而且大多 ...
- [Python爬虫] 之十六:Selenium +phantomjs 利用 pyquery抓取一点咨询数据
本篇主要是利用 pyquery来定位抓取数据,而不用xpath,通过和xpath比较,pyquery效率要高. 主要代码: # coding=utf-8 import os import re fro ...