[Biojava-dev] StAX questions

Michael L. Heuer heuermh@acm.org
Tue, 26 Nov 2002 17:22:38 -0500 (EST)


Hello,

Two more questions about StAX,

1.  would it be possible to make DispatchOnElement.ByQName and friends
non-final?  I end up duplicating the funcationality of DispatchOnElement
in subclasses of StAXContentHandlerBase just because I need to parse
attributes, for instance.

2.  when you return an object from public void endTree(StAXContext ctx),
where does it go?  I've used StAX on several occassions now and always
have this feeling like I'd have to type a lot less if I fully understood
what was going on.

given

<parent>
  <children>
    <child name="child0" />
    <child name="child1" />
  </children>
</parent>

one has something like

class ParentHandler ...
{
  private List children;
  private ChildHandler childHandler = new ChildHandler();

  public void startTree(..) { children = new ArrayList(); }
  public void startElement(...)
  {
    if ("child".equals(qName))
      dctx.delegate(childHandler);
  }

  private class ChildHandler ...
  {
    private Child child;

    public void startTree(..) { child = new Child(); }
    public void endTree(..) { return child; }
    public void startElement(...)
    {
      child.setName(...attr.getValue...);
    }
  }
}

where's the best place to add child to the children list in ParentHandler?

Maybe I'd like to see something like

public void startElement(...)
{
  if ("child".equals(qName))
  {
    children.add( (Child) dctx.delegate(childHandler) );
  }
}

Thank you in advance,

   michael