为什么org.apache.xerces.parsers.SAXParser不会跳过utf8编码的xml中的BOM? [英] why org.apache.xerces.parsers.SAXParser does not skip BOM in utf8 encoded xml?

查看:248
本文介绍了为什么org.apache.xerces.parsers.SAXParser不会跳过utf8编码的xml中的BOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有utf8编码的xml。
此文件包含BOM文件的开头。
所以在解析过程中我遇到了org.xml.sax.SAXParseException:prolog中不允许使用内容。
我无法从文件中删除这3个字节。
我无法将文件加载到内存中并在此处删除它们(文件很大)。
因此,出于性能原因,我正在使用SAX解析器,如果它们在标记之前存在,则只想跳过这3个字节。
我应该为此继承InputStreamReader吗?

I have an xml with utf8 encoding. And this file contains BOM a beginning of the file. So during parsing I am facing with org.xml.sax.SAXParseException: Content is not allowed in prolog. I can not remove those 3 bytes from the files. I can not load file into memory and remove them here (files are big). So for performance reasons I'm using SAX parser and want just to skip those 3 bytes if they are present before "" tag. Should I inherit InputStreamReader for this?

我是java新手 - 请告诉我正确的方法。

I'm new in java - show me the right way please.

推荐答案

之前已经出现了,我找到了 Stack Overflow上的答案,当它发生在我身上时。链接的答案使用 PushbackInputStream 来测试BOM。

This has come up before, and I found the answer on Stack Overflow when it happened to me. The linked answer uses a PushbackInputStream to test for the BOM.

这篇关于为什么org.apache.xerces.parsers.SAXParser不会跳过utf8编码的xml中的BOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆