OC-PM: SAX ponderings

Wilson, Douglas dgwilson at sonomasystems.net
Thu Dec 5 15:25:44 CST 2002


First let me say thanks again Kip for the presentation last night!
I've now at least a start on what SAX is about...

I was thinking about the theoretical problem Ryan
mentioned last night, and how it might be handled with SAX.
The problem as I recall was, say you have a document like this:
...
<x>
  <a>...</a>
  <b>...</b>
  <c>...</c>
</x>
...

And you want to randomly eliminate one of the children of x (or maybe
you want to randomly pick one to keep and eliminate the rest), and
you don't know in advance how many children x has.

Am I wrong in thinking that after you come across the x start_element
event, you would then have to pass events on to a buffer (lets say you
want to randomly eliminate a child), then when you get to the x end_element
event you'd have to then pass the buffer through a filter which would
eliminate the
unlucky nth child.

Or if you wanted to keep only one child, then you could pass events from
each child to a
separate buffer (in the same way as the Picking a Random Line from a File
Perl Cookbook recipe, deciding whether to create a new buffer, save a
child to it, and throw away the old buffer as you come across each child).

I see a XML::Filter::Sort::BufferMgr module and related modules, would that
be the
way to go? Looking at it, it only handles 5 different events, which may or
may not
be good enough. Or am I completely on the wrong track?
That's entirely possible too :-)

Cheers,
-Doug



More information about the Oc-pm mailing list