简体   繁体   English

关于将 StAX 与无限流的 xml 文件一起使用的问题

[英]Question about using StAX with an endless stream of xml files

I have a server running that sends one xml file every second (which eventually needs to be upgraded to 800 files/second).我有一台运行的服务器每秒发送一个 xml 文件(最终需要升级到 800 个文件/秒)。 The client I wrote that listens to the server, processes the first file perfectly fine, but as soon as the 1st file is completely processed and it tries to go to the second file, I get the following error:我编写的侦听服务器的客户端可以完美地处理第一个文件,但是一旦第一个文件被完全处理并尝试转到第二个文件,我就会收到以下错误:

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[164,6] Message: The processing instruction target matching "[xX][mM][lL]" is not allowed. javax.xml.stream.XMLStreamException: ParseError at [row,col]:[164,6] 消息:不允许匹配“[xX][mM][lL]”的处理指令目标。

I'm assuming this is caused because it is reading the start if the next xml file <?xml version="1.0" encoding='null' standalone='no'?> and that causes the error?我假设这是因为它正在读取开始,如果下一个 xml 文件<?xml version="1.0" encoding='null' standalone='no'?>并且导致错误?

This exception is caused, like you assumed, by XML declaration (which is part of prolog) not being before first element in the document according to spec .就像您假设的那样,此异常是由 XML 声明(它是 prolog 的一部分)引起的,而不是根据spec在文档中的第一个元素之前。 Depending on what implementation you use to read the file you should reset your reader or close and create new instance for each file.根据您用于读取文件的实现,您应该重置读取器或关闭并为每个文件创建新实例。

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

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