Defining an XML format for a 2D array (Grid) of items
I need to define an XML format and then read it in ActionScript3, which will be storing:
- the number of rows and columns in a grid
- the horizontal and vertical spacing in pixels
- the size of each square in the grid in pixels
- an optional label for each square in the grid
- an optional hyperlink for each square in the grid
The following is the kind of thing that would meet my needs at the moment, which demonstrates the four square types:
<?xml version="1.0" encoding="utf-8"?>
<grid columns="2" rows="2" horizontalSpacing="10" verticalSpacing="10"
squareWidth="300" squareHeight="300">
<column>
开发者_StackOverflow社区 <square label="Square(1,1)" url="http://example.com/1/1/" />
<square label="Square(1,2)" />
</column>
<column>
<square url="http://example.com/2/2/" />
<square />
</column>
</grid>
My questions are things akin to "Should there be units on the spacing and size? (like 10px or 300px)" and "How bad would it be to use a XHTML subset of (table
, td
, tr
with a
elements in each cell)."
But really I'm fishing for any precedent, ideas, or best practices. Particularly as they are relevant to processing such a file in ActionScript3. The goal is to be able to read the grid properties and to define a function that will give back a square's label and url given a row and column. (The easy thing about this format is that getting a square is just a matter of indexing into children of the grid node by integer... first column, then row.)
Couldn't you use JSON instead? It seems more adapted for this sort of task
You don't really need the <column>
tag at all. Just have a big list of <square>
's. The use your columns and rows attributes to define the width and height.
精彩评论