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

Ordering in SAX filter

  • From: Mansour Al Akeel <mansour.alakeel@g...>
  • To: "xml-dev@l... Developers" <xml-dev@l...>
  • Date: Sat, 17 May 2008 23:39:25 -0300

Ordering in SAX filter
I don't know if this is the correct place to post SAX and Java question, 
but I couldn't find any appropriate list.
I need to process some elements in a SAX filter only when a condition 
occurs. The problem that this condition occurs later, and after all the 
events for the elements I need to process are fired. For example:

<root>
    <elementsGroup>
       <element ../>
       <element ../>
       <element ../>
       <element ../>
    </elementsGroup>
    <someCondition>
       ......
    </someCondition>
    .....
</root>

I need to process the elements when this condition occurs or does not 
occur. I need to be able to pass these events down to the next filter.
The idea I have is to write a wrapper class for every event and store 
these event in a queue, and when this condition occur, I can do the 
processing I need and then pass the events down the stream. For example, 
a wrapper class for startElement would be like:

===============================================================
package saxEvents;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

public class ElementStartEvent extends SAXEvent {

    private String uri;
    private String localName;
    private String qName;
    private Attributes atts;

    public ElementStartEvent(String uri, String localName, String qName,
            Attributes atts) {
        this.uri = uri;
        this.localName = localName;
        this.qName = qName;
        this.atts = atts;
    }

    @Override
    public void fire() throws SAXException {
        getContentHandler().startElement(uri, localName, qName, atts);
    }
}
===================================================

Then in my filter, when the startElement is invoked, I can create an 
object from the wrapper class and queue it. Then when done and meet the 
condition I need, I can iterate over the queue (linkedList) and fire 
every single event in the list.

I need to know if someone has a better and easier idea ?  and if this 
approach has been implemented so that I don't have to write all the 
event classes from scratch.

Thank you.






[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


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.