Package javax.xml.parsers

Examples of javax.xml.parsers.SAXParser


        sw.write(">\n");
        this.writeContentsOn(is, sw);
        sw.write("\n</");
        sw.write("rs");
        sw.write('>');
        SAXParser p = SAXParserFactory.newInstance().newSAXParser();
        try {
            p.parse(new ByteArrayInputStream(sw.toString().getBytes()), this);
            TRANSLATIONS_OK++;
            TRANSLATIONS_LINECOUNT += this.countLinesIn(out.toString());
        } catch (org.xml.sax.SAXParseException sax) {
            TRANSLATIONS_FAILED++;
            int column = sax.getColumnNumber();


      return valid;
   }

   private static void parse(InputStream xmlIs, final EntityResolver resolver)
   {
      SAXParser parser;
      try
      {
         parser = FACTORY.newSAXParser();
      }
      catch (Exception e)
      {
         throw new IllegalStateException("Failed to instantiate a SAX parser: " + e.getMessage());
      }

      try
      {
         parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", true);
      }
      catch (SAXException e)
      {
         throw new IllegalStateException("Schema validation feature is not supported by the parser: " + e.getMessage());
      }

      try
      {
         parser.parse(xmlIs, new DefaultHandler()
         {
            public void warning(SAXParseException e)
            {
            }

    }
   
    public static void parseFile(File file) throws ParserConfigurationException, SAXException, IOException {
        XMLPropertiesHandler handler;
        SAXParserFactory factory;
        SAXParser parser;
       
        handler = new XMLPropertiesHandler();
        factory = SAXParserFactory.newInstance();
        parser = factory.newSAXParser();
        parser.parse(file, handler);
    }

    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
   
    boolean validating = JRProperties.getBooleanProperty(JRProperties.EXPORT_XML_VALIDATION);   
    saxParserFactory.setValidating(validating);

    SAXParser saxParser = saxParserFactory.newSAXParser();
    //XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    XMLReader xmlReader = saxParser.getXMLReader();

    xmlReader.setFeature("http://xml.org/sax/features/validation", validating);

    JRXmlDigester digester = new JRXmlDigester(xmlReader);
    digester.push(this);

        parserFactory.setNamespaceAware(true);

        // Now create a SAXParser object
        ArrayList<BibtexEntry> bibItems = null;
        try {
            SAXParser parser = parserFactory.newSAXParser(); // May throw
            // exceptions
            MedlineHandler handler = new MedlineHandler();
            // Start the parser. It reads the file and calls methods of the
            // handler.
            parser.parse(stream, handler);

            // Switch this to true if you want to make a local copy for testing.
            if (false) {
                stream.reset();
                FileOutputStream out = new FileOutputStream(new File("/home/alver/ut.txt"));

   * Creates a new instance of digester. The created digester is ready for
   * parsing report definition files.
   */
  public static JRXmlDigester createDigester() throws ParserConfigurationException, SAXException
  {
    SAXParser parser = createParser();
    JRXmlDigester digester = new JRXmlDigester(parser);
   
    //normally not required because schemaSource is set, but keeping to be safe
    setComponentsInternalEntityResources(digester);
   

  parserFactory.setNamespaceAware(true)
  // Now create a SAXParser object


  try{
      SAXParser parser = parserFactory.newSAXParser(); //May throw exceptions
      BibTeXMLHandler handler = new BibTeXMLHandler();
      // Start the parser. It reads the file and calls methods of the handler.
      parser.parse(stream, handler);
      // When you're done, report the results stored by your handler object
      bibItems = handler.getItems();
     
  }catch (javax.xml.parsers.ParserConfigurationException e1){
      e1.printStackTrace();

  {
    try
    {
      final CdaResponseParser contentHandler = new CdaResponseParser();
      final SAXParserFactory factory = SAXParserFactory.newInstance();
      final SAXParser parser = factory.newSAXParser();
      final XMLReader reader = parser.getXMLReader();

      try
      {
        reader.setFeature("http://xml.org/sax/features/xmlns-uris", false);
      }

   
    public opensearchdescriptionReader(final String path) {
        this();
        try {
            final SAXParserFactory factory = SAXParserFactory.newInstance();
            final SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(path, this);
        } catch (final Exception e) {
            Log.logException(e);
        }
    }

   
    public opensearchdescriptionReader(final InputStream stream) {
        this();
        try {
            final SAXParserFactory factory = SAXParserFactory.newInstance();
            final SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(stream, this);
        } catch (final Exception e) {
            Log.logException(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.