如何在XML文件中构建多维数组?

Tho*_*ler 3 java xml arrays xml-serialization multidimensional-array

我有一个多维数组,如:

String[][] greatCities = new String[2][2];
greatCities[0][0] = "Vancouver";
greatCities[0][1] = "Charlottetown";
greatCities[1][0] = "Zürich";
greatCities[1][1] = "Bern";
Run Code Online (Sandbox Code Playgroud)

现在我正在寻找一种将这个数组的结构(无代码)保存到xml文件的好方法.我到目前为止的最佳解决方案是:

<GreatCities>
  <Item index0="0" index1="0">Vancouver</Item>
  <Item index0="0" index1="1">Charlottetown</Item>
  <Item index0="1" index1="0">Zürich</Item>
  <Item index0="1" index1="1">Bern</Item>
</GreatCities>
Run Code Online (Sandbox Code Playgroud)

有没有人有更好的解决方案?

Euc*_*lid 7

因为它实际上是一个数组数组......

<GreatCity index =0>
   <Name index="0">Vancouver</Name>
   <Name index="1">Charlottetown</Name>
</GreatCity>
etc...
Run Code Online (Sandbox Code Playgroud)