当数据包含不可显示的字符时,JAXB输出无效的XML [英] JAXB outputting invalid XML when data contains non-displayable chars

查看:153
本文介绍了当数据包含不可显示的字符时,JAXB输出无效的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JAXB 2.2.5从JAXB模型输出Xml,数据从数据库中填充,有时数据库包含不应显示的字符,例如

I'm using JAXB 2.2.5 to output Xml from a JAXB Model, the data is populated from the database and occasionally the database contains non-displayable characters that it should not such as

0x1a 

若是,那么JAXB只输出这个字符就输出无效的Xml,它不应该逃脱它吗?

If it does then JAXB outputs invalid Xml by just outputting this char as is, shouldn't it escape it or something ?

更新

我想知道是否有任何实现可以解决这个问题,也许是Eclipselink MOXy吗?

I wonder if there are any implementations that do fix this problem, maybe Eclipselink MOXy does ?

EDIT

我尝试了修复非法字符问题的解决方法,但它以不合需要的方式更改了输出。

I tried the workaround that fixes the illegal char issue however it changes the output in an undesirable way.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><metadata created="2013-02-27T11:40:04.009Z" xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><cdstub-list count="1" offset="0"><cdstub id="w237dKURKperVfmckD5b_xo8BO8-" ext:score="100"><title>fred</title><artist></artist><track-list count="5"/></cdstub></cdstub-list></metadata>

<?xml version="1.0" ?><metadata xmlns:ext="http://musicbrainz.org/ns/ext#-2.0" xmlns="http://musicbrainz.org/ns/mmd-2.0#" created="2013-02-27T11:39:15.394Z"><cdstub-list count="1" offset="0"><cdstub id="w237dKURKperVfmckD5b_xo8BO8-" ext:score="100"><title>fred</title><artist></artist><track-list count="5"></track-list></cdstub></cdstub-list></metadata>

ie < track-list count =5/> 已成为< track-list count =5>< / track-list> 这是不受欢迎的,我不知道为什么它正在这样做。

i.e <track-list count="5"/> has become <track-list count="5"></track-list>which is undesirable, I'm not sure why it is doing this.

推荐答案

这显然是一个常见的问题 - 并标记为一个bug JAXB生成非法XML字符

It is apparently a common problem - and marked as a bug JAXB generates illegal XML characters.

您可以在Escape非法字符

这篇关于当数据包含不可显示的字符时,JAXB输出无效的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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