0
我做了處理大量關閉的xml文件(動態)工作,但我不能確定具體的Java對象@XmlRootElement。我認爲我需要將xml片段轉換爲Map對象。Spring Batch的 - 和解組XML文件,JSON - 動態XML
對於爲例:我不知道文件的結構,它是動態的。我有兩個xml文件,我嘗試只執行一個處理這兩個文件的作業。
文件1 -
<Pessoa>
<campos>
<campo>
<nome>Carlos</nome>
<sobrenome>Silva</sobrenome>
</campo>
<campo>
<nome>Carlos</nome>
<sobrenome>Silva</sobrenome>
</campo>
</campos>
</Pessoa>
文件2 -
<Parent>
<childs>
<child>Lala</campo>
<child>Lala</campo>
</childs>
</Parent>
的ItemReader和ItemProcessor中必須執行這兩個文件。這些文件是動態的,我不能通知要綁定的類。 例如:我的一個擴展StaxEventItemReader
Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
// It is possible? The Map.class hasn't @XmlRootElement declaration
//unmarshaller.setClassesToBeBound(Map.class);
setUnmarshaller(unmarshaller);
setFragmentRootElementNames(new String[] {"Pessoa", "Parent"});
使用Spring批來處理該文件是可能的讀者,根據我的要求是什麼?
謝謝!
如果沒有階級結構用你爲什麼不直接從XML到JSON?您還沒有一個類來生成JSON如果我理解正確這 – efekctive
您可以使用Jsoup把XML到內存中,然後使用JsonBuilder創建兒子文件 – efekctive
在這種情況下,我已經轉換XML文件中的JSON並在春季批量加工。我認爲這個過程會很昂貴。 –