Examples of XMLReader


Examples of org.xml.sax.XMLReader

        // Parse document
        try {

            BasicUserMappingContentHandler contentHandler = new BasicUserMappingContentHandler();

            XMLReader parser = XMLReaderFactory.createXMLReader();
            parser.setContentHandler(contentHandler);
            parser.parse(mapFile.getAbsolutePath());

            mappingTime = mapFile.lastModified();
            mapping = contentHandler.getUserMapping();

        }
View Full Code Here

Examples of org.xml.sax.XMLReader

            throws XQueryException {
        this.loadDocument(is);
    }

    private static final XMLReader getXMLReader(final DocumentTableBuilder handler, final boolean parseAsHtml, final boolean resolveEntity) {
        final XMLReader myReader;
        try {
            if(parseAsHtml) {
                Class clazz = ClassResolver.get(HTML_PARSER_CLASS);
                assert (clazz != null);
                myReader = ObjectUtils.<XMLReader> instantiate(clazz);
            } else {
                final SAXParserFactory factory;
                if(hasSunXerces) {
                    factory = ObjectUtils.instantiate("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", null);
                } else {
                    factory = SAXParserFactory.newInstance();
                }
                factory.setNamespaceAware(true);
                SAXParser parser = factory.newSAXParser();
                myReader = parser.getXMLReader();
            }
        } catch (Exception e) {
            throw new XQRTException("Creating SAX XMLReader failed", e);
        }
        // setup handlers (requires saxHandler)
        myReader.setContentHandler(handler);
        try {
            myReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
            myReader.setFeature("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors.
            if(!parseAsHtml) {
                myReader.setFeature("http://apache.org/xml/features/validation/dynamic", true); // The parser will validate the document only if a grammar is specified.  
                myReader.setFeature("http://apache.org/xml/features/validation/schema", true); // Turn on XML Schema validation by inserting an XML Schema validator into the pipeline.  
            }
        } catch (Exception e) {
            throw new XQRTException("Configuaring SAX XMLReader failed.", e);
        }
        // setup entity resolver
        if(resolveEntity) {
            org.apache.xml.resolver.CatalogManager catalog = org.apache.xml.resolver.CatalogManager.getStaticManager();
            catalog.setIgnoreMissingProperties(true);
            catalog.setPreferPublic(true);
            catalog.setUseStaticCatalog(false);
            EntityResolver resolver = new org.apache.xml.resolver.tools.CatalogResolver(catalog);
            myReader.setEntityResolver(resolver);
        }
        return myReader;
    }
View Full Code Here

Examples of org.xml.sax.XMLReader

                  throws IOException, ClassNotFoundException {

    try {

      // Obtiene una instancia del parser
      XMLReader parser = XMLReaderFactory.createXMLReader(parserName);

      // Configura los manejadores en el parser
      parser.setContentHandler((ContentHandler)this);
      parser.setErrorHandler((ErrorHandler)this);

      parser.setFeature("http://xml.org/sax/features/validation", true);
      if (schemavalidate) {
        parser.setFeature("http://apache.org/xml/features/validation/schema", true);
      }

      // Parsea el documento
      parser.parse(new InputSource(xml));

    } catch (SAXParseException e) {
      System.err.println(e.getMessage());
    } catch (SAXException e) {
      System.err.println(e.getMessage());
View Full Code Here

Examples of org.xml.sax.XMLReader

    public void parse(String sXMLData)
      throws InstantiationException,IllegalAccessException,ClassNotFoundException,IOException,SAXException {
        // This method parses an XML document into a ShoppingBasket instace

        // local variables
        XMLReader parser;
        Parser sax1Parser;
        StringBufferInputStream oStrBuff;
        InputSource ioSrc;

        if (DebugFile.trace) {
          DebugFile.writeln ("Begin ShoppingBasket.parse(String)");
          DebugFile.incIdent();
        }

        try {
          if (DebugFile.trace) DebugFile.writeln ("XMLReaderFactory.createXMLReader(" + DEFAULT_PARSER_NAME + ")");

          parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME);
        }
        catch (Exception e) {
            if (DebugFile.trace) DebugFile.writeln ("ParserFactory.makeParser(" + DEFAULT_PARSER_NAME + ")");

            sax1Parser = ParserFactory.makeParser(DEFAULT_PARSER_NAME);

            parser = new ParserAdapter(sax1Parser);
            if (DebugFile.trace)
              DebugFile.writeln("warning: Features and properties not supported on SAX1 parsers.");
        }
        try {
          parser.setFeature(NAMESPACES_FEATURE_ID, DEFAULT_NAMESPACES);
          parser.setFeature(VALIDATION_FEATURE_ID, DEFAULT_VALIDATION);
        }
        catch (SAXException e) {
        }

      // parse file
      parser.setContentHandler(this);
      parser.setErrorHandler(this);

      oStrBuff = new StringBufferInputStream(sXMLData);
      ioSrc = new InputSource(oStrBuff);
      parser.parse(ioSrc);
      oStrBuff.close();

      if (DebugFile.trace) {
        DebugFile.decIdent();
        DebugFile.writeln ("End ShoppingBasket.parse()");
View Full Code Here

Examples of org.xml.sax.XMLReader

      documentURI = inputSource.getSystemId();

      // saxFilter.clear();
      saxFilter.setDocumentURI(documentURI);

      XMLReader xmlReader = XMLReaderFactory.createXMLReader();
      xmlReader.setContentHandler(saxFilter);

      rdfHandler.startRDF();
      xmlReader.parse(inputSource);
      rdfHandler.endRDF();
    }
    catch (SAXParseException e) {
      Exception wrappedExc = e.getException();
      if (wrappedExc == null) {
View Full Code Here

Examples of org.xml.sax.XMLReader

   * @throws SAXException     if a validation error occurs
   * @throws RuntimeException DOCUMENT ME!
   */
  public void validate(Document document) throws SAXException {
    if (document != null) {
      XMLReader reader = getXMLReader();

      if (errorHandler != null) {
        reader.setErrorHandler(errorHandler);
      }

      try {
        reader.parse(new DocumentInputSource(document));
      } catch (IOException e) {
        throw new RuntimeException("Caught and exception that should "
            + "never happen: " + e);
      }
    }
View Full Code Here

Examples of org.xml.sax.XMLReader

      this.xmlReader = (SAXWriter) reader;
    } else if (reader instanceof XMLFilter) {
      XMLFilter filter = (XMLFilter) reader;

      while (true) {
        XMLReader parent = filter.getParent();

        if (parent instanceof XMLFilter) {
          filter = (XMLFilter) parent;
        } else {
          break;
View Full Code Here

Examples of org.xml.sax.XMLReader

         boolean validate = glob.getProperty().get("javax.xml.parsers.validation", false);
         spf.setValidating(validate);
         //if (log.isLoggable(Level.FINE)) log.trace(ME, "XML-Validation 'javax.xml.parsers.validation' set to " + validate);

         SAXParser sp = spf.newSAXParser();
         XMLReader parser = sp.getXMLReader();

         //parser.setEntityResolver(EntityResolver resolver);
         //parser.setFeature("http://xml.org/sax/features/validation", true);
         //parser.setFeature("http://apache.org/xml/features/validation/schema", true);
         //parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
         parser.setContentHandler(this);
         parser.setErrorHandler(this); // !!! new MyErrorHandler ());
        
         /*
         final boolean useLexicalHandler = true; // switch on to get CDATA events
         */
         if (this.useLexicalHandler) {
            try {
               parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); // register for startCDATA() etc. events
            }
            catch (SAXNotRecognizedException e) {
               log.warning("The SAX parser does not support the LexicalHandler interface, CDATA sections can't be restored" + e.toString());
            }
            catch (SAXNotSupportedException e) {
               log.warning("The SAX parser does not support the LexicalHandler interface, CDATA sections can't be restored" + e.toString());
            }
         }

         parser.parse(xmlData);
      }
      catch (Throwable e) {
         // In startElement(), endElement() you can use directly
         // throw new org.xml.sax.SAXException("Can't parse it", e);

View Full Code Here

Examples of org.xml.sax.XMLReader

    public void parse(String sXMLSource)
        throws InstantiationException,IllegalAccessException,ClassNotFoundException,IOException,SAXException {

        // local variables
        XMLReader parser;
        Parser sax1Parser;
        long time, timeBefore=0, timeAfter=0, memory, memoryBefore=0, memoryAfter=0;

        if (DebugFile.trace) {
          timeBefore = System.currentTimeMillis();
          memoryBefore = Runtime.getRuntime().freeMemory();
        }

        try {
          if (DebugFile.trace)
            DebugFile.writeln("XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME)");

          parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME);
        }
        catch (Exception e) {
            sax1Parser = ParserFactory.makeParser(DEFAULT_PARSER_NAME);
            parser = new ParserAdapter(sax1Parser);
            if (DebugFile.trace)
              DebugFile.writeln("warning: Features and properties not supported on SAX1 parsers.");
        }

      // parse file
      parser.setContentHandler(this);
      parser.setErrorHandler(this);

      if (DebugFile.trace)
        DebugFile.writeln("XMLReader.parse(" + sXMLSource + ")");

      parser.parse(sXMLSource);

      if (DebugFile.trace) {
        memoryAfter = Runtime.getRuntime().freeMemory();
        timeAfter = System.currentTimeMillis();
View Full Code Here

Examples of org.xml.sax.XMLReader

          throws TransformerException
  {

    try
    {
      XMLReader reader = (inputSource instanceof SAXSource)
                         ? ((SAXSource) inputSource).getXMLReader() : null;
                        
      if (null == reader)
      {
        try {
          javax.xml.parsers.SAXParserFactory factory=
              javax.xml.parsers.SAXParserFactory.newInstance();
          factory.setNamespaceAware( true );
          javax.xml.parsers.SAXParser jaxpParser=
              factory.newSAXParser();
          reader=jaxpParser.getXMLReader();
         
        } catch( javax.xml.parsers.ParserConfigurationException ex ) {
          throw new org.xml.sax.SAXException( ex );
        } catch( javax.xml.parsers.FactoryConfigurationError ex1 ) {
            throw new org.xml.sax.SAXException( ex1.toString() );
        } catch( NoSuchMethodError ex2 ) {
        }
        catch (AbstractMethodError ame){}
        if(null == reader)
          reader = XMLReaderFactory.createXMLReader();
      }

      try
      {
        reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
                          true);
      }
      catch (org.xml.sax.SAXException se)
      {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.