Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Ordering in SAX filter

From: Mansour Al Akeel <mansour.alakeel@-----.--->
To: "xml-dev@-----.---.--- ----------" <-------@-----.---.--->
Date: 5/18/2008 2:40:00 AM
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.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent