[Home] [By Thread] [By Date] [Recent Entries]

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

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]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member