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

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

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

問題描述

我需要 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:

預期輸出 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)絡非常龐大)

  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 時可以使用類似的技術.

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.

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(liá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服務賬戶查看上傳文件到谷歌驅(qū)動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 国产精品亚洲片在线播放 | 9久9久9久女女女九九九一九 | 欧美久久久网站 | 亚洲色图婷婷 | 黑人精品 | 亚洲精品久久久久久一区二区 | 日本一区二区三区四区 | 久久久夜色精品亚洲 | 日韩成人在线免费视频 | 激情视频中文字幕 | 中文字幕免费在线观看 | 精品视频一区二区三区 | 亚洲第一视频网 | 国产伦精品一区二区三区视频金莲 | 久久精品欧美电影 | 黄色av网站在线免费观看 | 久久久久成人精品 | 黄频免费 | www.国产.com | 国产美女福利在线观看 | 在线观看特色大片免费网站 | 高清一区二区视频 | 性高朝久久久久久久3小时 av一区二区三区四区 | 国产精品mv在线观看 | 成人免费淫片aa视频免费 | 欧美日韩在线播放 | 亚洲欧美一区二区三区在线 | 国产专区在线 | av天空| 日日摸日日添日日躁av | 中文字幕高清在线 | 狠狠干夜夜草 | 精品久久久久久亚洲精品 | 国产成人高清 | 日韩av福利在线观看 | 中文字幕亚洲一区二区三区 | 久久首页 | 麻豆一区一区三区四区 | 日日操夜夜操天天操 | 欧美成人a∨高清免费观看 欧美日韩中 | 欧美成人精品激情在线观看 |