第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

JAXB:在解組XML文檔期間如何忽略名稱空間?

JAXB:在解組XML文檔期間如何忽略名稱空間?

動(dòng)漫人物 2019-10-08 15:29:42
我的架構(gòu)指定了一個(gè)名稱空間,但是文檔沒(méi)有。在JAXB解組(XML->對(duì)象)期間忽略名稱空間的最簡(jiǎn)單方法是什么?換句話說(shuō),我有<foo><bar></bar></foo>代替,<foo xmlns="http://tempuri.org/"><bar></bar></foo>
查看完整描述

3 回答

?
拉莫斯之舞

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊

我相信您必須將名稱空間添加到xml文檔中,例如,使用SAX過(guò)濾器。


這意味著:


用新類定義一個(gè)ContentHandler接口,該接口將在JAXB獲取它們之前攔截SAX事件。

定義一個(gè)XMLReader,它將設(shè)置內(nèi)容處理程序

然后將兩者鏈接在一起:


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

    }

}


查看完整回答
反對(duì) 回復(fù) 2019-10-08
?
滄海一幻覺(jué)

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

我在XMLFilter解決方案中遇到編碼問(wèn)題,因此我使XMLStreamReader忽略名稱空間:


class XMLReaderWithoutNamespace extends StreamReaderDelegate {

    public XMLReaderWithoutNamespace(XMLStreamReader reader) {

      super(reader);

    }

    @Override

    public String getAttributeNamespace(int arg0) {

      return "";

    }

    @Override

    public String getNamespaceURI() {

      return "";

    }

}


InputStream is = new FileInputStream(name);

XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(is);

XMLReaderWithoutNamespace xr = new XMLReaderWithoutNamespace(xsr);

Unmarshaller um = jc.createUnmarshaller();

Object res = um.unmarshal(xr);


查看完整回答
反對(duì) 回復(fù) 2019-10-08
  • 3 回答
  • 0 關(guān)注
  • 783 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)