Java-转换Html特殊字符的问题

Java-转换Html特殊字符的问题,java,xpath,htmlcleaner,Java,Xpath,Htmlcleaner,我试图通过使用Xpath和JAVA来解析HTML页面。这是我的密码: /** Cleaning the html file */ /** the 'doc' variable is a String containing the whole html file */ TagNode tagNode = new HtmlCleaner().clean(doc); Document doc2 = new DomSerializer( n

我试图通过使用Xpath和JAVA来解析HTML页面。这是我的密码:

        /** Cleaning the html file */
        /** the 'doc' variable is a String containing the whole html file */
        TagNode tagNode = new HtmlCleaner().clean(doc);
        Document doc2 = new DomSerializer( new CleanerProperties() ).createDOM(tagNode);




        XPath xpath = XPathFactory.newInstance().newXPath();

        /** xpath request */
        Object dates_experience = xpath.evaluate("/html/body/div[3]/div/div/div[2]/div/div/div[2]/div[4]/div/div[3]/h4/span[2]", doc2, XPathConstants.NODESET);

        NodeList nodes = (NodeList) dates_experience;
        String s;
        for (int i = 0; i < nodes.getLength(); i++) {
            s = org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(nodes.item(i).getTextContent());
            System.out.println(s); 
        }
而不是那些字符:

é, è, ', à, û, ...etc
例如,我有以下输入:

décembre 2010 - décembre 2010)
février 2010 - juin 2010)
juillet 2009 - septembre 2009)
juin 2009 - juin 2009)
juillet 2008 - août 2008)
我的程序生成以下输出:

d�cembre 2010 - d�cembre 2010)
f�vrier 2010 - juin 2010)
juillet 2009 - septembre 2009)
juin 2009 - juin 2009)
juillet 2008 - ao�t 2008)
你能帮我解决这个问题吗


谢谢。

我想你应该*取消*转义,而不是转义:
StringEscapeUtils.unescapethml4(String)

你能发布一些数据输入/输出示例吗?似乎你不必转义或取消转义它们,只要你尊重数据的字符集。“doc”字符串是否正确加载,并带有有效的字符集?文档字符串必须与文档的字符集一起加载,如HTML文件标记中所定义。是的,我按照HTML文件中的定义在UTF-8中加载了它,因此它不必(取消)转义。UTF-8涵盖了您发布的所有字符。如果您正在查看该页面的HTML源代码,是否有aé或其他内容?我尝试了您的解决方案,但是,无论我是否使用unescape,eā。。。字符替换为“?”。所以我的输出是d?cembre,ao?t。另外,当我执行system.out.println(doc)时,这些字符也被替换为“?”。
d�cembre 2010 - d�cembre 2010)
f�vrier 2010 - juin 2010)
juillet 2009 - septembre 2009)
juin 2009 - juin 2009)
juillet 2008 - ao�t 2008)