Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


         * Constructs a Client that connects to the given port in terse
         * output mode.
         */
        public Client(String address, int port) throws IOException {
            this(address, port, false);
            fParser = new SAXParser();
            fParser.setDocumentHandler(this);
            fParser.setErrorHandler(this);
        }
View Full Code Here


        return parser;
    }

    synchronized SAXParser getSAXParser() {
        if (fSAXParser != null) {
            SAXParser parser = (SAXParser) fSAXParser.get();
            if (parser != null) {
                return parser;
            }
        }
        // REVISIT:  when schema handles XML 1.1, will need to
        // revisit this (and the practice of not prepending an XML decl to the annotation string
        XML11Configuration config = new XML11Configuration(fSymbolTable);
        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        SAXParser parser = new SAXParser(config);
        fSAXParser = new SoftReference(parser);
        return parser;
    }
View Full Code Here

    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Create a stylesheet using SAX.

    // Instantiate a Xerces SAX parser.
    SAXParser saxparser = new SAXParser();

    // Create an empty StylesheetRoot. The createStylesheetRoot(String baseURI) method is not
    // part of the XSLTProcessor interface, so must use the underlying XSLTEngineImpl object.
    // The baseURI is for resolving relative URIs. If null is sent, defaults to the current
    // directory.
    StylesheetRoot stylesheet = ((XSLTEngineImpl)processor).createStylesheetRoot(null);

    // Set up a StylesheetHandler (a SAX DocumentHandler) to receive events
    // as the Stylesheet is parsed.
    StylesheetHandler stylesheetHandler
      = new StylesheetHandler((XSLTEngineImpl)processor, stylesheet);

    // Set the StylesheetHandler to listen to SAX events from the SAX parser.
    saxparser.setDocumentHandler(stylesheetHandler);

    // Parse foo.xsl, sending SAX events to stylesheetHandler, which fills in the
    // StylesheetRoot object.
    saxparser.parse("foo.xsl");

    // Do a SAX-driven transform.

    // Reset the parser for a new parse.
    saxparser.reset();
    // Set the processor Stylesheet property, telling the processor which stylesheet to use.
    processor.setStylesheet(stylesheet);
    // Set the processor to act as a DocumentHandler, receiving SAX events from the
    // SAX parser.
    saxparser.setDocumentHandler(processor);
    // Set the SAX Parser lexical handler to the XSLTProcessor, so the SAX parser
    // can handle lexical events in the XML source, such as the occurrence of comment nodes.
    saxparser.setProperty("http://xml.org/sax/properties/lexical-handler", processor);
    // Set the processor to output the result to the screen.
    processor.setOutputStream(System.out);
    // Parse foo.xml, sending SAX events to the processor, which sends output
    // to a stream.
    saxparser.parse("foo.xml");
  }
View Full Code Here

    }

    // private methods
    private synchronized void writeToSAX(ContentHandler handler) {
        // nothing must go wrong with this parse...
        SAXParser parser = fGrammar.getSAXParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        parser.setContentHandler(handler);
        try {
            parser.parse(aSource);
        } catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        } catch (IOException i) {
View Full Code Here

                    parser = XMLReaderFactory.createXMLReader();
                }
                // If something went wrong with the factory
                // just use our own SAX parser.
                catch (SAXException se) {
                    parser = new SAXParser();
                }
                try {
                    parser.setFeature(NAMESPACE_PREFIXES, true);
                    namespacePrefixes = true;
                }
View Full Code Here

                    parser = XMLReaderFactory.createXMLReader();
                }
                // If something went wrong with the factory
                // just use our own SAX parser.
                catch (SAXException se) {
                    parser = new SAXParser();
                }
                try {
                    parser.setFeature(NAMESPACE_PREFIXES, true);
                    namespacePrefixes = true;
                }
View Full Code Here

        return parser;
    }

    synchronized SAXParser getSAXParser() {
        if (fSAXParser != null) {
            SAXParser parser = (SAXParser) fSAXParser.get();
            if (parser != null) {
                return parser;
            }
        }
        // REVISIT:  when schema handles XML 1.1, will need to
        // revisit this (and the practice of not prepending an XML decl to the annotation string
        XML11Configuration config = new XML11Configuration(fSymbolTable);
        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        SAXParser parser = new SAXParser(config);
        fSAXParser = new SoftReference(parser);
        return parser;
    }
View Full Code Here

                        parser = XMLReaderFactory.createXMLReader();
                    }
                    // If something went wrong with the factory
                    // just use our own SAX parser.
                    catch (SAXException se) {
                        parser = new SAXParser();
                    }
                    try {
                        parser.setFeature(NAMESPACE_PREFIXES, true);
                        namespacePrefixes = true;
                        // If this is a Xerces SAX parser set the security manager if there is one
View Full Code Here

    }

    // private methods
    private synchronized void writeToSAX(ContentHandler handler) {
        // nothing must go wrong with this parse...
        SAXParser parser = fGrammar.getSAXParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        parser.setContentHandler(handler);
        try {
            parser.parse(aSource);
        }
        catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        }
        catch (IOException i) {
            // ditto with above
        }
        // Release the reference to the user's ContentHandler.
        parser.setContentHandler(null);
    }
View Full Code Here

    }
   
    public void testLocatorReturnsNullSystemIDWithoutRelativeURL()
      throws ParsingException, IOException {
       
        XMLReader reader = new SAXParser();
        reader = new LocatorFilter(reader);
        Builder builder = new Builder(reader);
        InputStream in = new FileInputStream("data/nonquirky.xhtml");
        builder.build(in);
       
View Full Code Here

TOP

Related Classes of org.apache.xerces.parsers.SAXParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.