JaxBを使用して、大きなXMLの少数の子のみをマーシャリング解除したいと思います。XML構造は次のようなものです。
<root>
<child1>
<child1.1>
<child1.1.1/>
<child2.1.1/>
<child2.1.1/>
<child3.1.1/>
<child3.1.1/>
</child1.1>
</child1>
</root>
ここで私はにマーシャルを解除したいと思いchild1.1.1, child2.1.1 and child3.1.1
ます。ルート要素のJavaクラスを作成したくなく、子をマーシャリングしたいだけです。
現在、ルート要素のマーシャリングを解除し、子オブジェクトをそこから取り出しています。
JAXBContext jc = JAXBContextFactory.createContext(new Class[] {RootType.class}, null);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("D:/Projects/test.xml");
RootType root = (RootType)unmarshaller.unmarshal(xml);
Child1.1.1[] child1.1.1 = root.getChild1().getChild1.1[0].getChild1.1.1()
もう1つの問題は、複数の子を扱うことです。個々の子要素をアンマーシャリングしながら、
どのように対処しますか?child2.1.1 and child3.1.1