Menu Home

Java DOM解析GBK编码的XML

final String XMLString = ""
                    + ""
                    + "张三"
                    + "";

private static final DocumentBuilderFactory sDocBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = sDocBuilderFactory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(xmlString.getBytes("GBK"));
Reader reader = new InputStreamReader(is, "GBK");
InputSource source = new InputSource(reader);
Document doc = builder.parse(source);

Categories: java xml

Tagged as:

lnmcc

Leave a Reply

Your email address will not be published.