In that case, I would just deal with it sequentially, like you did.
Basically, I would ignore the labels entirely.

Also 'dict' is just the label you are using in that xml. It was "database"
that I was reacting to - there are a fairly widely adopted set of practices
associated with databases (and some of these practices are good while
others may be irrelevant or sometimes even bad). Anyways, let's not worry
about that now.

Here's the the code I'd use to parse the xml (I am leaving out the parts
that you use to processed the parsed xml):

require 'xml/sax/x2j'

x2jclass 'freecell'

'Items' x2jDefn
  /    := Table : Table=: i.0 0
  dict := Table=: Table,Row : Row=: ''
  date    := Row=: Row,<y
  real    := Row=: Row,<y
  integer := Row=: Row,<y
  string  := Row=: Row,<y
)

Note that this code places its definitions in a locale named 'freecell'. If
you want to do other things after entering these lines you would need to
either (a) run these lines in their own script file (locale reverts at the
end of loading a script) or you would need an explicit command: cocurrent
'base'

With the above definition and a variable named 'sample' which matches the
xml you posted, here's how it looks in action:

   process_freecell_ sample
+--------------------+--------------------+---------+---+----+
|2010-07-25T02:55:34Z|2001-01-01T00:29:10Z|94163764 |23 |Loss|
+--------------------+--------------------+---------+---+----+
|2010-07-05T19:46:01Z|2001-01-01T00:08:44Z|192061342|108|Win |
+--------------------+--------------------+---------+---+----+

I hope this helps.

Thanks,

-- 
Raul





On Wed, Feb 12, 2014 at 4:28 PM, Brian Schott <schott.br...@gmail.com>wrote:

> I am thinking of this data as a data set, perhaps is used the word database
> too cavalierly. My purpose was to see if there was any trends in my
> personal Freecell game playing skills. If the data format changes, I guess
> I will alter my code, in this case.
>
> You are way ahead of me on thinking about generalizing this example. I am
> not really familiar with dicts in general, and only saw the <dict> scheme
> as a way to collect the data. I have never imagined dealing with a complex
> file like the one in your examples. So it is hard for me to follow your
> example. But presently I have no immediate needs for xml beyond the one I
> showed.
>
>
>
>
> On Wed, Feb 12, 2014 at 4:08 PM, Raul Miller <rauldmil...@gmail.com>
> wrote:
>
> > I can throw together an example or two, but first allow me to make an
> > observation, and ask a question:
> >
> > The observation is that the xml itself is a bit messy. Every data item
> you
> > have mentioned corresponds to a pair of [consecutive] xml elements. And,
> as
> > is usual for xml, the result is somewhat overspecified. This means that
> we
> > have a variety of ways of extracting the data and it's worth just a few
> > moments of thought about potential variations:
> >
> > (1) We can rely on sequence for all elements in a dict - they will not
> > change, or
> > (2) We can only rely on sequence for the minimal pairs needed to identify
> > the data items of a dict, or
> >  (3) We cannot rely on the sequence but instead must fail with an error
> > when it is violated.
> >
> > And there's a similar line of questions about potential future extensions
> > of the underlying dataset - are they errors, or to be ignored or to be
> > handled according to some uniform rule? Or is it simply that you would
> plan
> > on fixing the code if the format changed?
> >
> > (This could be simpler if the xml were structured differently.)
> >
> > Since you have suggested that this represents a database, I thought I
> would
> > know the answers to these questions, but looking at your implementation I
> > see something different, and I would like to hear your thoughts before
> > tackling any implementation(s).
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> >
> --
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to