久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

JAXB 解組未知 XML 內(nèi)容的子集

JAXB Unmarshalling an subset of Unknown XML content(JAXB 解組未知 XML 內(nèi)容的子集)
本文介紹了JAXB 解組未知 XML 內(nèi)容的子集的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我需要 unmarshall 未知 XML 內(nèi)容的子集,使用該未編組的對象,我需要修改一些內(nèi)容并重新綁定相同的 XML 內(nèi)容(子集) 與原始 XML.

I have a requirement to unmarshall a subset of Unknown XML content, with that unmarshalled object, I need modify some contents and re-bind the same XML content(subset) with the Original XML.

輸入 XML 示例:

<Message>
    <x>
    </x>
    <y>
    </y>
    <z>
    </z>
    <!-- Need to unmarshall this content to "Content" - java Object -->
    <Content>
        <Name>Robin</Name>
        <Role>SM</Role>
        <Status>Active</Status>
    </Content>
.....
</Message>

需要單獨解組 <Content> 標記,保持其他 XML 部分相同.需要修改<Content>標簽中的元素,并將修改后的XML部分與原文綁定,如下圖:

Need to unmarshall the <Content> tag alone, by keeping the other XML part as same. Need to modify the elements in <Content> tag and bind the modified XML part with the original as shown below:

預(yù)期輸出 XML:

<Message>
    <x>
    </x>
    <y>
    </y>
    <z>
    </z>
    <!-- Need to unmarshall this content to "Content" - java Object -->
    <Content>
        <Name>Robin_123</Name>
        <Role>Senior Member</Role>
        <Status>1</Status>
    </Content>
.....
</Message>

我的問題:

  1. 此要求的可能解決方案是什么?(除了 DOM 解析 - 因為 XML 網(wǎng)絡(luò)非常龐大)

  1. What is the possible solution for this Requirement ? (Except DOM parsing - as XML contnet is very huge)

JAXB2.0 中是否有任何選項可以執(zhí)行此操作?

Is there any option to do this in JAXB2.0 ?

請就此提出您的建議.

推薦答案

考慮使用 StAX API.

對于給定的示例,此代碼使用 Content 元素的根元素創(chuàng)建一個 DOM 文檔:

For the given sample, this code creates a DOM document with a root element of the Content element:

class ContentFinder implements StreamFilter {
  private boolean capture = false;

  @Override public boolean accept(XMLStreamReader xml) {
    if (xml.isStartElement() && "Content".equals(xml.getLocalName())) {
      capture = true;
    } else if (xml.isEndElement() && "Content".equals(xml.getLocalName())) {
      capture = false;
      return true;
    }
    return capture;
  }
}

XMLInputFactory inFactory = XMLInputFactory.newFactory();
XMLStreamReader reader = inFactory.createXMLStreamReader(inputStream);
reader = inFactory.createFilteredReader(reader, new ContentFinder());
Source src = new StAXSource(reader);
DOMResult res = new DOMResult();
TransformerFactory.newInstance().newTransformer().transform(src, res);
Document doc = (Document) res.getNode();

這可以是 作為 /transform/dom/DOMSource.html" rel="nofollow">DOMSource.

This can then be passed to JAXB as a DOMSource.

在輸出時重寫 XML 時可以使用類似的技術(shù).

Similar techniques can be used when rewriting the XML on output.

JAXB 似乎不直接接受 StreamSource,至少在 Oracle 1.7 實現(xiàn)中是這樣.

JAXB doesn't seem to accept a StreamSource directly, at least in the Oracle 1.7 implementation.

這篇關(guān)于JAXB 解組未知 XML 內(nèi)容的子集的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(fā)(Google 驅(qū)動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅(qū)動api服務(wù)賬戶查看上傳文件到谷歌驅(qū)動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務(wù)帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 欧美精品在线一区二区三区 | 超碰男人天堂 | 一区二区精品视频 | 亚洲一区二区免费视频 | 日韩av在线一区 | 国产精品国产三级国产aⅴ浪潮 | 国产精品视频在线免费观看 | av在线播放不卡 | 91视频在线观看 | 欧美一区二区三区在线视频 | 超碰精品在线 | 精品久久久久久久久久久院品网 | 999免费观看视频 | 欧美一区二区久久 | 久久久青草婷婷精品综合日韩 | 欧美精品一区在线观看 | 久久久久综合 | 日韩欧美三级在线 | www.精品国产| 成人av鲁丝片一区二区小说 | 亚洲精品视频导航 | 国产精品久久久久久网站 | 日韩电影免费在线观看中文字幕 | 国产精品美女久久久久aⅴ国产馆 | 亚洲欧美日韩精品久久亚洲区 | 奇米四色影视 | 亚洲福利精品 | 亚洲国产精品99久久久久久久久 | 在线免费观看a级片 | 国产伦一区二区三区视频 | 一区二区三区四区在线视频 | 国产精品永久在线观看 | 日批免费观看 | 日本在线中文 | 婷婷五月色综合 | 中文字幕av在线播放 | 国产色播av在线 | 岛国av免费看 | 亚洲免费在线 | 国产日韩欧美精品 | 国产精品久久久久久一级毛片 |