简体   繁体   English

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

[英]special characters in xml stax parser file

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

When i read the file using stax parser and writing it to the new file it creates which makes the invalid xml file because there is no &amp in the new file. 当我使用stax解析器读取文件并将其写入新文件时,它会创建无效的xml文件,因为新文件中没有&amp。

Below is working for me : 下面为我​​工作:

// 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM