Package javax.xml.parsers

Examples of javax.xml.parsers.SAXParser


   *             If a SAX error occurred.
   * @throws IOException
   *             If an I/O error occurred.
   */
  protected List<URI> load(final InputStream in) throws SAXException, IOException {
    SAXParser saxParser;

    // Use the default (non-validating) parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      saxParser = factory.newSAXParser();
    } catch (final ParserConfigurationException ex) {
      throw new SAXException(ex);
    }

    // Parse the XML
    groups = new LinkedList<URI>();
    saxParser.parse(in, this);
    return groups;
  }


    list = new LinkedList<DefaultItem>();
    // Use the default (non-validating) parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      // Parse the input
      final SAXParser saxParser = factory.newSAXParser();

      final InputStream is = ItemsXMLLoader.class.getResourceAsStream(uri.getPath());

      if (is == null) {
        throw new FileNotFoundException("cannot find resource '" + uri
            + "' in classpath");
      }
      try {
        saxParser.parse(is, this);
      } finally {
        is.close();
      }
    } catch (final ParserConfigurationException t) {
      LOGGER.error(t);

    list = new LinkedList<DefaultCreature>();
    // Use the default (non-validating) parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      // Parse the input
      final SAXParser saxParser = factory.newSAXParser();

      InputStream is = CreaturesXMLLoader.class.getResourceAsStream(ref.getPath());

      if (is == null) {
        throw new FileNotFoundException("cannot find resource '" + ref
            + "' in classpath");
      }

      try {
        saxParser.parse(is, this);
      } finally {
        is.close();
      }
    } catch (final ParserConfigurationException t) {
      logger.error(t);

    loadedSpells = new LinkedList<DefaultSpell>();
    // Use the default (non-validating) parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      // Parse the input
      final SAXParser saxParser = factory.newSAXParser();

      final InputStream is = SpellXMLLoader.class.getResourceAsStream(uri.getPath());

      if (is == null) {
        throw new FileNotFoundException("cannot find resource '" + uri
            + "' in classpath");
      }
      try {
        saxParser.parse(is, this);
      } finally {
        is.close();
      }
    } catch (final ParserConfigurationException t) {
      logger.error(t);

                + keyword.replace(' ', '_').replace("%", "%25")
                + "&prop=revisions&rvprop=content&format=xml");
        final SAXParserFactory factory = SAXParserFactory.newInstance();

        // Parse the input
        final SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(httpClient.getInputStream(), this);

        final String response = getText();

        if (response.startsWith("#REDIRECT")) {
          // extract the new keyword

            logger.error("Failed to load " + RIDDLES_EXAMPLE_XML);
            return;
          }
        }

        SAXParser parser;

        // Use the default (non-validating) parser
        final SAXParserFactory factory = SAXParserFactory.newInstance();
        try {
          parser = factory.newSAXParser();
          parser.parse(in, this);
        } catch (final Exception e) {
          logger.error(e);
        } finally {
          try {
            in.close();

   public void parse(InputStream io) throws ParserException {
      try {
         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setValidating(true);
         factory.setNamespaceAware(true);
         SAXParser parser = factory.newSAXParser();
         XMLReader reader = parser.getXMLReader();

         reader.setContentHandler(this);
         reader.setErrorHandler(new Frame2ParseErrorHandler());
         reader.setEntityResolver(new Frame2EntityResolver());

   * @return The handler for chaining
   */
  public static <CTX extends XMLContext, D extends IXMLDocument<CTX>> CTX parse (IInputSource input, D handler, CTX context) {
    try {
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser parser = factory.newSAXParser();
     
      XMLReader<CTX> xmlHandler = new XMLReader<CTX>(handler, context);
     
      org.xml.sax.XMLReader reader = parser.getXMLReader();
      reader.setContentHandler(xmlHandler);
      reader.setDTDHandler(xmlHandler);
      reader.setEntityResolver(xmlHandler);
      reader.setErrorHandler(xmlHandler);
     

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(true);

    // Create a JAXP SAXParser
    SAXParser saxParser = spf.newSAXParser();

    // Set the schema language
    saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

    // Set the schema source.
    saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaSource);

    // Get the SAX XMLReader
    XMLReader xmlReader = saxParser.getXMLReader();

    // Set the ErrorHandler
    xmlReader.setErrorHandler(new MyErrorHandler(System.err));

    // Parse the XML source

  /**
   * Obtain info of JAXP implementation classes.
   */
  private void obtainJAXPImplInfo() {
    try {
      SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
      _suite.saxParser = saxParser.getClass().getName();

      Transformer trans = SAXTransformerFactory.newInstance().newTransformer();
      _suite.transformer = trans.getClass().getName();
    }
    catch (Exception e) {

TOP

Related Classes of javax.xml.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.