栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JAXB:如何在解组XML文档期间忽略名称空间?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAXB:如何在解组XML文档期间忽略名称空间?

我相信你必须将名称空间添加到xml文档中,例如,使用SAX过滤器。

这意味着:

  • 用一个新类定义一个ContentHandler接口,该接口将在JAXB获得它们之前拦截SAX事件。
  • 定义一个XMLReader,它将设置内容处理程序
    然后将两者链接在一起:
public static Object unmarshallWithFilter(Unmarshaller unmarshaller,java.io.File source) throws FileNotFoundException, JAXBException {    FileReader fr = null;    try {        fr = new FileReader(source);        XMLReader reader = new NamespaceFilterXMLReader();        InputSource is = new InputSource(fr);        SAXSource ss = new SAXSource(reader, is);        return unmarshaller.unmarshal(ss);    } catch (SAXException e) {        //not technically a jaxb exception, but close enough        throw new JAXBException(e);    } catch (ParserConfigurationException e) {        //not technically a jaxb exception, but close enough        throw new JAXBException(e);    } finally {        FileUtil.close(fr); //replace with this some safe close method you have    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/456548.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号