在Java中消除糟糕的XML [英] Sanitizing bad XML in Java

查看:78
本文介绍了在Java中消除糟糕的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用返回无效的XML的第三方库,因为它包含无效字符以及未声明的实体。我需要使用Java XML解析器来解析这个XML,但是它很窒息。

I'm using a third-party library that returns "XML" that is not valid, because it contains invalid characters, as well as non-declared entities. I need to use a Java XML parser to parse this XML, but it's choking.

是否有一种通用的方法来清理这个XML以使它变得有效?

Is there a generic way to sanitize this XML so that it becomes valid?

推荐答案

我认为您的选择类似于:

I think your options are something like:


  • 标记汤

  • < a href =http://jtidy.sourceforge.net/ =nofollow noreferrer> JTidy

  • 自己滚动。

前两个更重量级,因为它们旨在解析生成错误的HTML。如果你知道这些问题是由于编码和实体造成的,那么我建议你自己动手:

The first two are more heavyweight, given that they're designed to parse ill formed HTML. If you know that the problems are due to encoding and entities, but otherwise well formed I'd suggest you roll your own:


  • 标准化编码为UTF-8

  • 对>和<之间的文本使用标准编码器字符(文本实体)。

这篇关于在Java中消除糟糕的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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