I'm a bad Canadian.
After 20 years of not ice skating I somehow got the idea the
other day that what I really wanted to do was go
skating. My hockey career was cut short at the tender age
of six, when my parents decided to move from Ontario (the
province, not the town in California) to Saudi Arabia. I
haven't laced up the skates since; that is, until this past
weekend.
Amazingly enough, I wasn't all that bad at it (that's not to
say I was good, but at least I didn't bail). They
have these crummy little plastic skates which you could
rent, which seemed to do the trick, but it was a little
intimidating when people would jet by you at Mach 10 wearing
a $350 pair of ice skates and you're moving a slightly
faster than walking speed with a piece of plastic digging
into your foot.
Actually, what was more scary
than that was the onslaught of 6 year old skaters tripping
and falling in front of you every couple of minutes which
you repeatedly have to dodge. I guess it makes you a better
skater in the long run though.
More on XML:
So what exactly is all this key->key->value stuff that I've
been talking about anyway? The best way of describing it
would be a means of traversing a tree. The XML document
itself
is really just a big tree of nodes which holds data about
particular things.
<foo> <key>value</key> <foo2> <key>value</key> </foo2> </foo>Could be represented logically as:
foo / \ key foo2 / \ value key \ valueWe can build something like this somewhat easily using the XML::Parser module and using Style => 'Tree' for the output. Here's a snippet of the code using Data::Dumper to print out the resulting data structure:
use XML::Parser; use Data::Dumper;Which should spit out something with lots of references roughly in the shape of the tree that we're trying to build. The problem with this is that it's still a bit of a ways off, and you'll need to still heavily parse this to get in into any kind of reasonable shape. A module like XML::Simple will do this for you (I believe someone mentioned it on here), although I have to admit, I'm not crazy about the syntax.my $xml = <<END; <foo> <key>value</key> <foo2> <key>value</key> </foo2> </foo> END
$x = new XML::Parser( Style => 'Tree' ); $y = $x->parse( $xml );
print Dumper( $y );
When I initially attacked the problem, I didn't bother to use the 'Tree' style output with XML::Parser and was instead just setting up the different Start, End and Char handlers and then using a couple of stacks to build the tree. I've been struggling with this over the last few days and when I think I've just about got everything working, it seems like my logic is a bit off and the resulting data structure doesn't quite work. Oh well, c'est la vie. The struggles of a computer programmer.