dom4j只認本地編碼的xml檔案而不認UTF-8編碼的嗎?

dcomli發表於2004-02-25
我試圖用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檔案嗎?謝謝。

相關文章