dom4j只认本地编码的xml文件而不认UTF-8编码的吗?

04-02-25 dcomli
我试图用dom4j解析UTF-8编码的文件时出错:

Caused by: org.dom4j.DocumentException: Error on line 32 of document : The valu e of attribute "Name" associated with an element type "Participant" must not con tain the '<' character. Nested exception: The value of attribute "Name" associat ed with an element type "Participant" must not contain the '<' character. at org.dom4j.io.SAXReader.read(SAXReader.java:355) at org.dom4j.io.

但我通过

javax.xml.transform.Transformer transformer =

javax.xml.transform.TransformerFactory.newInstance().newTransformer();

//Notice this first sentence below, which resolves the problem of Chinese

transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING, "gb2312");

transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");

transformer.transform(new javax.xml.transform.dom.DOMSource(doc),

new javax.xml.transform.stream.StreamResult(outFile));

转了以后,dom4j就认了。

有没有开关可以使dom4j认UTF-8编码的xml文件吗?谢谢。

猜你喜欢