xml stax解析器文件中的特殊字符

时间:2013-03-26 16:25:08

标签: java xml xml-parsing stax

original xml file: 
<root> <article>
<artists><artist role="A&amp;R Staff" id="1">Vance</artist><artists></article>
</root>

当我使用stax解析器读取文件并将其写入新文件时,它会创建无效的xml文件,因为新文件中没有&amp; amp。

1 个答案:

答案 0 :(得分:-2)

以下是我的工作:

// This can be any InputStream
InputStream is;
XMLInputFactory factory = XMLInputFactory.newInstance();
// Set this property to handle special HTML characters like & etc.
factory.setProperty(XMLInputFactory.IS_COALESCING, true);
// Now use the factory to get the EventReader from the InputStream
XMLEventReader eventReader = factory.createXMLEventReader(is);