Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


   * @param handler The handler to use for parsing.
   * @throws Exception When parsing failed.
   */
  private void parse(InputStream stream, ContentHandler handler)
      throws Exception {
    SAXParser parser = new SAXParser();
    parser.setContentHandler(handler);

    // Complete list of features of the xerces parser:
    // http://xml.apache.org/xerces2-j/features.html
    parser.setFeature("http://xml.org/sax/features/validation", false);
    parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

    parser.parse(new InputSource(stream));
  }
View Full Code Here


      InputSource inputSource = createInputSource(context, source);
      if (source == null) {
        throw context.BadParameter("File, InputStream, URL or string expected");
      }

      SAXParser parser = new SAXParser();
      setupParser(context, parser, features);
      handler = new SAXHandler(context, callbacks, userdata);
      parser.setErrorHandler(handler);
      parser.setDTDHandler(handler);
      parser.setEntityResolver(handler);
      parser.setContentHandler(handler);
      parser.parse(inputSource);
      listener = handler.getListener();
      if (listener != null) {
        throw context.XMLError("Parsing failed", listener);
      }
      return Any.create(userdata);
View Full Code Here

    InputStream inputStream = input.openInputStream();
    try {
      InputSource inputSource = new InputSource(inputStream);
      SaxEventAdapter saxEventAdapter = new SaxEventAdapter(input, eventHandler);
      try {
        XMLReader xmlReader = new SAXParser();
        xmlReader.setContentHandler(saxEventAdapter);
        xmlReader.setDTDHandler(saxEventAdapter);
        xmlReader.setEntityResolver(saxEventAdapter);
        xmlReader.setErrorHandler(saxEventAdapter);

        // Enable full namespace handling.
        xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
        xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);

        xmlReader.parse(inputSource);
      } catch (SAXException saxException) {
        if (!saxEventAdapter.getExceptionMessages().contains(saxException.getMessage())) {
          eventHandler.add(new SaxAlert(new SourcePosition(input),
                                        Severity.ERROR, saxException));
        }
View Full Code Here

     * @throws java.io.IOException if input can't be read
     * @throws org.xml.sax.SAXException if XML can't be parsed
     */
    public synchronized ListAccumulator parse(InputSource input) throws IOException, SAXException {

        XMLReader reader = new SAXParser();
        reader.setContentHandler(this);
        reader.parse(input);

        return ba;
    }
View Full Code Here

      } else {
        _conn.setKeysToLowerCase();
        _conn.setFieldNameToUpperCase(false);
      }

      SAXParser parser = new SAXParser();
      parser.setContentHandler(this);

      File file = new File(_fileName);
      if (!file.canRead()) {
        throw new FileNotFoundException("File not found: " + _fileName);
      }

      if (_log != null) _log.debug3("Using file: " + _fileName);

      //FileReader fr = new FileReader(_fileName);
      //parser.parse(new InputSource(fr));
      parser.parse(_fileName);

    } catch (SAXException e) {
      throw new SAXException("SOSImport.doImport: " + e.getMessage(), e);
    } catch (Exception e) {
      throw new Exception("SOSImport.doImport: " + e.getMessage(), e);
View Full Code Here

     * Create a new <code>SAXParserFactoryImpl</code> instance.
     */
    protected SAXParserImpl(boolean namespaces, boolean validation)
    throws ParserConfigurationException {
        this();
        SAXParser p=new SAXParser();
        try {
            p.setFeature("http://xml.org/sax/features/namespaces",namespaces);
        } catch (SAXException e) {
            throw new ParserConfigurationException("Cannot set namespace "+
                "awareness to "+namespaces);
        }
        try {
            p.setFeature("http://xml.org/sax/features/validation",validation);
        } catch (SAXException e) {
            throw new ParserConfigurationException("Cannot set validation to "+
                validation);
        }
        this.namespaces=namespaces;
View Full Code Here

    {
      // Fallback if this fails (implemented in createIncrementalSAXSource) is
      // to attempt Xerces-1 incremental setup. Can't do tail-call in
      // constructor, so create new, copy Xerces-1 initialization,
      // then throw it away... Ugh.
      IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
      this.fParseSomeSetup=dummy.fParseSomeSetup;
      this.fParseSome=dummy.fParseSome;
      this.fIncrementalParser=dummy.fIncrementalParser;
    }
  }
View Full Code Here

    catch(NoSuchMethodException e)
    {
      // Xerces version mismatch; neither Xerces1 nor Xerces2 succeeded.
      // Fall back on filtering solution.
      IncrementalSAXSource_Filter iss=new IncrementalSAXSource_Filter();
      iss.setXMLReader(new SAXParser());
      return iss;
    }
  }
View Full Code Here

    XmlBaseExtractor xmlBaseExtractor = new XmlBaseExtractor(is);
    return xmlBaseExtractor.getXMLBase();
  }

  public URI getXMLBase() throws Exception {
    SAXParser parser = new SAXParser();
    parser.setContentHandler(new MyHandler());
    parser.parse(is);
    return xmlBase;
  }
View Full Code Here

    {
      // Fallback if this fails (implemented in createIncrementalSAXSource) is
      // to attempt Xerces-1 incremental setup. Can't do tail-call in
      // constructor, so create new, copy Xerces-1 initialization,
      // then throw it away... Ugh.
      IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
      this.fParseSomeSetup=dummy.fParseSomeSetup;
      this.fParseSome=dummy.fParseSome;
      this.fIncrementalParser=dummy.fIncrementalParser;
    }
  }
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.