XMLStreamWriter에 번호를 writeCharacters (...)StAX - writeCharacters(), 중국어, 일본어 문자를 이스케이프 처리하지 않으려면 어떻게해야하나요?
writeCharacters (...) 메소드는 다음과 같은 &, <,>, 그리고 "문자를 이스케이프하는 데 사용됩니다.
(http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/StAX4.html에서)하지만 때 일부 중국어, 일본어 문자를 쓰고 출력 XML 파일은 "UTF-8"로 인코딩되지 않지만 "GBK"또는 "Shift-JIS"입니다. 중국어, 일본어 문자도 마찬가지로 이스케이프됩니다.
"汉语, 영어, に ほ ん ご"---> "& # x6c49; & # x8bed, 영어, & # x306b; & # x307b; & # x3093; & #의 x3054; "
그것을 해결하기 위해 어쨌든 거기
public static void main(String[] args) throws Exception {
// GBK
System.out.println("JVM default charset = " + Charset.defaultCharset());
String s = "汉语, English, にほんご";
XMLOutputFactory output = XMLOutputFactory.newInstance();
output.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
OutputStream out = new FileOutputStream("C:/aa.txt");
XMLStreamWriter writer = output.createXMLStreamWriter(out, "UTF-8");
// When output encoding is "UTF-8", result is something like:
// <?xml version='1.0' encoding='UTF-8'?><a>汉语, English, にほんご</a>
// When output encoding is "GBK", result is something like:
// <?xml version='1.0' encoding='GBK'?><a>汉语, English, にほんご</a>
writer.writeStartDocument();
writer.setDefaultNamespace("http://c");
writer.writeStartElement("http://c", "a");
writer.writeCharacters(s);
writer.writeEndElement();
writer.flush();
}
죄송합니다, 위의 의견이 옳지 않습니다! 나는 statckoverflow.com을 처음 사용합니다. 나는 자바 소스를 추가 할 것이다. – btpka3
귀하의 예는 내가 말한 것을 정확히 확인합니다. 모든 유니 코드 문자는 UTF-8을 사용하고 다른 문자 집합을 사용할 때 인코딩 된 경우 잘 인쇄됩니다. 그래서, 무엇이 잘못 되었나요? – AlexR
"UTF-8"을 사용하면 잘 ~~. 그러나 일반적으로 XML이 "GBK"로 인코딩되면 왜 중국어 문자가 이스케이프됩니까? 고객이 "GBK"사용을 주장하는 경우 기술적으로 수정할 수 있습니까? – btpka3