[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|