Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java xml stax解析器文件中的特殊字符 原始xml文件: 万斯_Java_Xml_Xml Parsing_Stax - Fatal编程技术网

Java 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&amp;R Staff" id="1">Vance</artist><artists></article> </root> 问题更可能出现在编写

当我使用stax解析器读取文件并将其写入它创建的新文件时,由于新文件中没有&,这使得xml文件无效。

以下内容适用于我:

original xml file: 
<root> <article>
<artists><artist role="A&amp;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);