Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.SAXParser


    {
      // 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

    protected Locator locator;
    protected Stack elements;
    protected StringBuffer text;

    public XmlReader(XmlProcessor processor) {
        this(processor, new SAXParser());
    }
View Full Code Here

    public static XMLReader getSaxParser(String parserName){
        try{
            Class parserClass = Class.forName(parserName);
            return (XMLReader) ClassUtil.newInstance(parserClass);
        }catch (ClassNotFoundException e) {
            return new SAXParser();
        }
    }
View Full Code Here

   * @return The newly created XML reader or null if unsuccessful.
   * @throws Exception
   */
  protected XMLReader createXMLReader() throws Exception
  {    
    SAXParser reader = null;
    try
    {
      reader = new org.apache.xerces.parsers.SAXParser(new XMLValidatorParserConfiguration());
     
      XMLConformanceDefaultHandler conformanceDefaultHandler = new XMLConformanceDefaultHandler();
      reader.setErrorHandler(conformanceDefaultHandler);
      reader.setContentHandler(conformanceDefaultHandler);
     
      // Older Xerces versions will thrown a NPE if a null grammar pool is set.
      if(grammarPool != null)
      {
        reader.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX + org.apache.xerces.impl.Constants.XMLGRAMMAR_POOL_PROPERTY, grammarPool);
      }
      reader.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX + org.apache.xerces.impl.Constants.ENTITY_RESOLVER_PROPERTY, new MyEntityResolver(uriResolver));
      reader.setFeature(org.apache.xerces.impl.Constants.XERCES_FEATURE_PREFIX + org.apache.xerces.impl.Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, false);
      reader.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.NAMESPACES_FEATURE, true);
      reader.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.NAMESPACE_PREFIXES_FEATURE, true);
    reader.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.VALIDATION_FEATURE, true);
    reader.setFeature(org.apache.xerces.impl.Constants.XERCES_FEATURE_PREFIX + org.apache.xerces.impl.Constants.SCHEMA_VALIDATION_FEATURE, true);
    }
    catch(Exception e)
    {
      LoggerFactory.getInstance().getLogger().log("Error creating XML reader for WSDL XML conformance validation.", ILogger.SEV_ERROR, e);
    }
View Full Code Here

              if(matcher.find()){
                xml = removeMatched(xml,matcher.start(),matcher.end());
              }
            }
           
            SAXParser parser = new SAXParser();
           
            String   dtd = getDTD(xml);
            String[] xsd = getXSD(xml);
           
            // Validation configuration
            if((dtd==null && xsd==null) || !params.getUseDTD()){
              parser.setFeature("http://xml.org/sax/features/validation", false);
            } else {
              parser.setFeature("http://xml.org/sax/features/validation", true);
              parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
            }
            if(xsd!=null && params.getUseDTD()){
//              parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
//              parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsd);
              parser.setFeature("http://apache.org/xml/features/validation/schema", true);
              parser.setFeature("http://xml.org/sax/features/namespaces", true);
            }
           
            parser.setFeature("http://xml.org/sax/features/use-entity-resolver2", true);
            parser.setEntityResolver(new DTDResolver(getDTDResolvers(),
                input.getFile().getLocation().makeAbsolute().toFile().getParentFile()));
            parser.setErrorHandler(new XMLValidationHandler(resource));
           
            parser.parse(new InputSource(new StringReader(xml))); //new ByteArrayInputStream(xml.getBytes(charset))));
           
          } catch(Exception ex){
            // ignore
            //HTMLPlugin.logException(ex);
          }
View Full Code Here

   * @param reader the input with the XML
   * @throws IOException
   * @throws SAXException
   */
  public void parse(Reader reader) throws IOException, SAXException {
    XMLReader parser = new SAXParser();
    parser.setContentHandler(new LogXMLHandler());
      parser.parse(new InputSource(reader));
  }
View Full Code Here

    /** the Entity Resolver */
    protected Resolver resolver = null;

    public XercesParser ()
    throws SAXException {
        this.parser = new SAXParser();

        this.parser.setFeature("http://xml.org/sax/features/validation", false);
        this.parser.setFeature("http://xml.org/sax/features/namespaces", true);
    }
View Full Code Here

  private boolean transform() {

    try {

      //configure parser
      SAXParser parser = new SAXParser();
      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.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdSource);
      parser.setErrorHandler(new DefaultHandler());

      //parse source file to validate it
      if (validate) {
        parser.parse(new InputSource(new BufferedInputStream(new FileInputStream(xmlSource))));
      }

      //transform
      dSource = new StreamSource(xmlSource);
      dResult = new StreamResult(xmlDestination);
      transf = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltTransformer));
      transf.transform(dSource, dResult);

      //configure parser
      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.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdDestination);
      parser.setErrorHandler(new DefaultHandler());

      //parse destination file to validate it
      if (validate) {
        parser.parse(new InputSource(new BufferedInputStream(new FileInputStream(xmlDestination))));
      }

      //transformation successful
      return true;
View Full Code Here

     * created and populated AppData structure
     */
    public AppData parseFile(String xmlFile, boolean skipValidation)
        throws Exception
    {
        SAXParser parser = new SAXParser();
       
        // set the Resolver for the database DTD
        DTDResolver dtdResolver = new DTDResolver();
        parser.setEntityResolver(dtdResolver);

        // We don't use an external content handler - we use this object
        parser.setContentHandler(this);
        parser.setErrorHandler(this);
       
        // Validate the input file
        parser.setFeature(
            "http://apache.org/xml/features/validation/dynamic", true);
        parser.setFeature("http://xml.org/sax/features/validation", true);

        FileReader fr = new FileReader (xmlFile);
        BufferedReader br = new BufferedReader (fr);
        try
        {
            InputSource is = new InputSource (br);
            parser.parse(is);
        }
        finally
        {
            br.close();
        }
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.