XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS