我正在使用XMLStreamReader
来解析一段xml:
XMLStreamReader rd = XMLInputFactory.newInstance().createXMLStreamReader(io_xml, "UTF-8");
...
if (eventType == XMLStreamConstants.START_ELEMENT) {
String name = rd.getLocalName();
if (name.equals("key")) {
String val = rd.getElementText();
}
}
问题是,我对以下字符串的读取错误:"<key>cami%C3%B5es%2Babc</key>"
org.junit.ComparisonFailure:
expected:<cami[%C3%B5es%]2Babc> but was:<cami[ C3 B5es ]2Babc>
我是否需要在XML中做任何特别的事情?我已经尝试将所有内容放在CDATA
部分内,但我得到了同样的错误。
使用“常规”解析器一切正常:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document parse = builder.parse(is);
String value = parse.getFirstChild().getTextContent();
...
答案 0 :(得分:0)
我明白了。问题出在代码的不同部分。 setter
set
不仅仅是{{1}}。