-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1http://www.zzxy.cn/manual/xml/xml_cn/xml_encoding.asp.htm
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32) - WinPT 1.0.0
Comment: www.pgp.org.cniD8DBQFFF0KYTaPfUVwGl08RApchAJ4jLAyh7LilJHw4Tc3+P2Yg2FXbiACg8zau
9UjkKGQ6njC0iKMFcg5nyGc=
=tpBD
-----END PGP SIGNATURE-----
Hash: SHA1http://www.zzxy.cn/manual/xml/xml_cn/xml_encoding.asp.htm
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32) - WinPT 1.0.0
Comment: www.pgp.org.cniD8DBQFFF0KYTaPfUVwGl08RApchAJ4jLAyh7LilJHw4Tc3+P2Yg2FXbiACg8zau
9UjkKGQ6njC0iKMFcg5nyGc=
=tpBD
-----END PGP SIGNATURE-----
try {
// Find a parser
DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder(); // Read the document
Document document = parser.parse(url); // Modify the document
Restructurer.processNode(document); // Write it out again
TransformerFactory xformFactory
= TransformerFactory.newInstance();
Transformer idTransform = xformFactory.newTransformer();
Source input = new DOMSource(document);
Result output = new StreamResult(System.out);
idTransform.setOutputProperty(OutputKeys.INDENT, "yes");
idTransform.setOutputProperty(OutputKeys.ENCODING,"GBK");
idTransform.transform(input, output); } catch (SAXException e) {
System.out.println(url + " is not well-formed.");
} catch (IOException e) {
System.out.println(
"Due to an IOException, the parser could not read " + url
);
} catch (FactoryConfigurationError e) {
System.out.println("Could not locate a factory class");
} catch (ParserConfigurationException e) {
System.out.println("Could not locate a JAXP parser");
} catch (TransformerConfigurationException e) {
System.out.println("This DOM does not support transforms.");
} catch (TransformerException e) {
System.out.println("Transform failed.");
} }上面是JAXP
强烈建议使用UTF-8编码
idTransform.setOutputProperty(OutputKeys.ENCODING,"GBK");
这两句实在太好了,就差在这地方,多谢这位仁兄!
真正的JAVA牛群,项目高手云集---19384516欢迎高手来此交流,有实际经验的最好。
菜鸟请勿入
即使进了你也搭不上话![em2]