churchatp1 2006年12月21日
如何读取xml中的中文
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document d;
db = dbf.newDocumentBuilder();
d = db.parse("D:/a.xml");
Element emt = d.getDocumentElement();
listAnalysisPoints = readAnalysisPoints(emt);
a.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>
<system>
<analysispoint>
<ifRun>yes</ifRun>
<type>AddByKeysGroup</type>
<table>demand</table>
<addcolumns>
<addcolumn>qty</addcolumn>
</addcolumns>
<groupcolumns>
<groupcolumn>factory_type</groupcolumn>
</groupcolumns>
<targetname>demandGroupBYKeys</targetname>
</analysispoint>
<analysispoint>
<ifRun>yes</ifRun>
<type>FilterByColumns</type>
<table>available_ship</table>
<filtercolumns>
<filtercolumn>
<colname>voyage_line_id</colname>
<filtertype>equal</filtertype>
<values>
<value>-</value>
<value>巴西</value>
</values>
</filtercolumn>
</filtercolumns>
<showcolumns>
<showcolumn>tonnage</showcolumn>
<showcolumn>voyage_line_id</showcolumn>
<showcolumn>isCOA</showcolumn>
</showcolumns>
<targetname>available_shipFilterOne</targetname>
</analysispoint>
</system>

在解析的时候就错了:
字符转换错误:“Unconvertible UTF-8 character beginning with 0xb0”(行号可能太小)。
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)
at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1072)
at org.apache.crimson.parser.InputEntity.isXmlDeclOrTextDeclPrefix(InputEntity.java:914)
at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:1183)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:653)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at com.firsttech.baosteel.analysisxml.reader.ConfigReader.reader(ConfigReader.java:36)
at com.firsttech.baosteel.Solution.solver(Solution.java:39)
at com.firsttech.baosteel.Solution.main(Solution.java:34)
...全文
176 点赞 收藏 4
写回复
4 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Java SE
创建于2007-09-28

3.4w+

社区成员

30.7w+

社区内容

Java 2 Standard Edition
社区公告
暂无公告