views:

73

answers:

2

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

Tx!

+1  A: 

Couldn't you use JSON instead? It seems more adapted for this sort of task

PatrickS
+1. XML is definitely a bad choice in this case.
back2dos
The issue is that it's being read by ActionScript, which has a built-in XML facility (no JSON by default) and the project is already using XML. So I'm trying to keep from introducing another dependency.
Hostile Fork
+1  A: 

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.

TandemAdam
Doing it this way means the code is actually quite simple (not much in the error handling department at this point): http://github.com/hostilefork/openzoom-squared/blob/master/viewer/SquaresDescriptor.as
Hostile Fork