こんにちは、次のグラフをシリアル化しています。
<grafo>
<nodo id="1">
<child id="2"/>
</nodo>
<nodo id="2">
<child id="3"/>
<child id="4"/>
</nodo>
<nodo id="3">
<child id="4"/>
</nodo>
<nodo id="4">
<child id="1"/>
</nodo>
子ノードをグラフ リスト内の他のノードの参照にリンクする必要があります。つまり、アンマーシャリング プロセスでは、新しいノードを作成して、その ID にリーダーを与える属性を設定するだけでは不十分です。すでにグラフ上にあるノードと属性を共有して、それを可能にするために、GraphConverter クラスの次の関数で試していました。
public Object unmarshal(HierarchicalStreamReader reader,UnmarshallingContext arg1) {
Grafo graph= new Grafo();
ArrayList<ArrayList<String>> handlechilds= new ArrayList<ArrayList<String>>();
while (reader.hasMoreChildren())
{
reader.moveDown();
Nodo node= new Nodo(reader.getAttribute("id"));
graph.nodos.add(node);
reader.moveDown();
//reader.getAttribute("id") ->> this just gives me the value of the fisrt node but not the anothers!!
reader.moveUp();
reader.moveUp();
}
return graph;
}
エッジの値を保存し、グラフを反復処理するために別の参照を追加することを考えていましたが、リーダーが子の 1 つを返すだけで、それらすべてが必要であることに気付きました。