Java xml stax解析器文件中的特殊字符 原始xml文件: 万斯
当我使用stax解析器读取文件并将其写入它创建的新文件时,由于新文件中没有&,这使得xml文件无效。以下内容适用于我:Java xml stax解析器文件中的特殊字符 原始xml文件: 万斯,java,xml,xml-parsing,stax,Java,Xml,Xml Parsing,Stax,当我使用stax解析器读取文件并将其写入它创建的新文件时,由于新文件中没有&,这使得xml文件无效。以下内容适用于我: original xml file: <root> <article> <artists><artist role="A&R Staff" id="1">Vance</artist><artists></article> </root> 问题更可能出现在编写
original xml file:
<root> <article>
<artists><artist role="A&R Staff" id="1">Vance</artist><artists></article>
</root>
问题更可能出现在编写部分,您能显示相应的代码吗?嗨,jorn,我添加了编写部分不要依赖
XmlEvent.toString()
生成格式良好的XML。使用
// 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);