How to structure a multidimensional array in an XML file?

I have a multidimensional array, for example:

String[][] greatCities = new String[2][2];
greatCities[0][0] = "Vancouver";
greatCities[0][1] = "Charlottetown";
greatCities[1][0] = "Zürich";
greatCities[1][1] = "Bern";

Now I am looking for a good way to save the structure (without code) of this array in an XML file. The best solution I have so far:

<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>

Does anyone have a better solution?

+3
source share
3 answers

As an efficient array of arrays ...

<GreatCity index =0>
   <Name index="0">Vancouver</Name>
   <Name index="1">Charlottetown</Name>
</GreatCity>
etc...
+7
source
<GreatCities>
  <Items index="0">
    <Item index="0">Vancouver</Item>
    <Item index="1">Charlottetown</Item>
  </Items>
  <Items index="1">
    <Item index="0">Zürich</Item>
    <Item index="1">Bern</Item>
  </Items>
</GreatCities>
+2
source

, (, xml). , , : XML-. :

<GreatCities>
  <GreatCity>
    <Name>Vancouver</Name>
    <Name>Charlottetown</Name>
  </GreatCity>
  <GreatCity />
  <GreatCity>
    <Name>Zürich</Name>
    <Name/>
    <Name>Bern</Name>
  </GreatCity>
</GreatCities>

/. XML-, .

+2

All Articles