使用JAXB解组XML而不会转义字符

使用JAXB解组XML而不会转义字符,第1张

使用JAXB解组XML而不会转义字符

你只需要更换

&#
&#
,因此呼叫

unmarshaller.unmarshal(new AmpersandingStream(new FileInputStream(...)));

import java.io.IOException;import java.io.InputStream;public class AmpersandingStream extends InputStream {    private InputStream in;    private boolean justReadAmpersand;    private String lookAhead = "";    public AmpersandingStream(InputStream in) {        this.in = in;    }    @Override    public int read() throws IOException {        if (!lookAhead.isEmpty()) { int c = lookAhead.prePointAt(0); lookAhead = lookAhead.substring(Character.charCount(c)); return c;        }        int c = in.read();        if (c == (int)'#' && justReadAmpersand) { c = (int)'a'; lookAhead = "mp;#";        }        justReadAmpersand = c == (int)'&';        return c;    }    @Override    public int available() throws IOException {        return in.available();    }    @Override    public void close() throws IOException {        in.close();    }    @Override    public synchronized void mark(int readlimit) {        in.mark(readlimit);    }    @Override    public boolean markSupported() {        return in.markSupported();    }    @Override    public int read(byte[] b) throws IOException {        return in.read(b);    }    @Override    public int read(byte[] b, int off, int len) throws IOException {        return in.read(b, off, len);    }    @Override    public synchronized void reset() throws IOException {        in.reset();    }    @Override    public long skip(long n) throws IOException {        return in.skip(n);    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5094130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存