qexo-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qexo-general] Using the SAX API


From: Alessandro Vernet
Subject: [Qexo-general] Using the SAX API
Date: Tue, 27 May 2003 15:02:11 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312

Per,

Thanks for your replies. When using the XMLPrinter, everything works perfectly.

Now I am trying to use the SAX API and I am getting unexpected results. For an example, see the attached program (Test.java). The XQuery expression is: let $a := <a/> return $a, and nothing is sent to the SAX ContentHandler when evaluating this expression.

For now I have resorted to using the XMLPrinter and parsing the result document to generate SAX events. This works, but of course introduces an unnecessary overhead.

Alex
import gnu.xquery.lang.XQuery;
import gnu.kawa.sax.ContentConsumer;
import java.io.StringWriter;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.Locator;
import org.xml.sax.Attributes;

public class Test {
    public static void main(String[] args) {
        try {
            XQuery xquery = new XQuery();
            ContentConsumer contentConsumer = new ContentConsumer(new 
DebugContentHandler());
            xquery.eval("let $a := <a/> return $a", contentConsumer);
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }

    public static class DebugContentHandler implements ContentHandler {
        public void characters(char ch[], int start, int length)
                throws SAXException {
        }

        public void endDocument()
                throws SAXException {
        }

        public void endElement(String namespaceURI, String localName,
                               String qName)
                throws SAXException {
        }

        public void endPrefixMapping(String prefix)
                throws SAXException {
        }

        public void ignorableWhitespace(char ch[], int start, int length)
                throws SAXException {
        }

        public void processingInstruction(String target, String data)
                throws SAXException {
        }

        public void setDocumentLocator(Locator locator) {
        }

        public void skippedEntity(String name)
                throws SAXException {
        }

        public void startDocument()
                throws SAXException {
        }

        public void startElement(String namespaceURI, String localName,
                                 String qName, Attributes atts)
                throws SAXException {
            System.out.println("startElement: " + namespaceURI + " " + qName);
        }

        public void startPrefixMapping(String prefix, String uri)
                throws SAXException {
        }
    }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]