[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: StAX XMLStreamWriter Oddities


xmlstreamwriter

> Also, I noticed that there is a patent filed on StAX by the StAX spec lead:

> http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%2F
> netahtml%2FPTO%2Fsearch-bool.html&r=1&f=G&l=50&co1=AND&d=PG01&s1=20030159112
> .PGNR.&OS=DN/20030159112&RS=DN/20030159112

What is so unique about StAX that it warrants a patent?
Can anyone enlighten me?

I looked at http://www.xml.com/pub/a/2003/09/17/stax.html, an
intro into StAX by Elliot Rusty Harold, and fail to see
any major breakthrough. Pull APIs have been around for a while,
and with the old MSXML 3.0 IMXeaderControl interface pull
parsing - like demonstrated with StAX - is easily possible
on top of SAX. Really, all you need is the capability
to interrupt/suspend a SAX parser, and then resume again.

The only "API" we need to define is a simple ParseEvent interface:
(I am not a Java programmer, so please forgive syntax errors)

  public interface ParseEvent {
    final int START_ELEMENT = 1;
    final int END_ELEMENT = 2;
    final int COMMENT = 3;
    final int PI = 4;
    <and so forth>
    int getEventType();
    XML Node getEventNode();
  }
where XMLNode (or rather a sub-class) exposes properties
appropriate to the event.

A Java adaption of IMXReaderControl could look like this:

public interface XMLReaderControl {
  final int READY = 0;      // status constant
  final int PARSING = 1;    // status constant
  final int SUSPENDED = 2;  // status constant
  void suspend();           // legal when PARSING
  void abort();             // legal when PARSING, SUSPENDED
  void resume();            // legal when SUSPENDED
  int getStatus();
}

The main pull parsing loop with a suspendable SAX parser could
then look like this, assuming the content handler implements
the ParseEvent interface described above and calls ReaderControl.suspend()
in the appropriate places:

   XMLReader.parse(inputSource);
   while (ReaderControl.getStatus() == SUSPENDED) {
     switch (ParseEvent.getEventType()) {
       case START_ELEMENT: 
         <cast getEventNode to ElementNode and process it>
         break;
       case END_ELEMENT:   
         <cast getEventNode to ElementNode and process it>
         break;
       case PI:           
         <cast getEventNode to PINode and process it>
         break;
       case COMMENT:      
         <cast getEventNode to CommentNode and process it>
         break;
       <and so forth>
     }
     ReaderControl.resume();
   }

One can likely implement a re-usable PullHandler class that
does most of the grunt work for that purpose. I would also
think of the ability to plug in an event filter class so
that one can iterate only over the events of interest.

I am not sure which streaming parser implement such suspend functionality,
I only know that Expat already has a patch (not part of the distro yet)
that achieves that. I don't think it should be a major problem to implement.

Karl


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.