我想使用 XMLStreamReader 来读取包含 Horizontal Tab ASCII Codes 的 XML 文件	
,例如:
<tag>foo	bar</tag>
并打印出来或写回另一个 xml 文件。
谷歌告诉我设置javax.xml.stream.isCoalescing
为true
in XMLInputFactory
,但我下面的测试代码没有按预期工作。
public static void main(String[] args) throws IOException, XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(factory.IS_COALESCING, true);
System.out.println("IS_COALESCING supported ? " + factory.isPropertySupported(factory.IS_COALESCING));
System.out.println("factory IS_COALESCING value is " +factory.getProperty(factory.IS_COALESCING));
String rawString = "<tag>foo	bar</tag>";
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(rawString));
System.out.println("reader IS_COALESCING value is " +reader.getProperty(factory.IS_COALESCING));
PrintWriter pw = new PrintWriter(System.out, true);
while (reader.hasNext())
{
reader.next();
pw.print(reader.getEventType());
if (reader.hasText())
pw.append(' ').append(reader.getText());
pw.println();
}
}
输出是
IS_COALESCING supported ? true
factory IS_COALESCING value is true
reader IS_COALESCING value is true
1
4 foo bar
2
8
但我想保持相同的水平选项卡,如:
IS_COALESCING supported ? true
factory IS_COALESCING value is true
reader IS_COALESCING value is true
1
4 foo	bar
2
8
我在这里想念什么?谢谢