Java 8 SAXParserFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SAXParserFactory class.

This code example shows how to use the following methods:newSAXParser, setNamespaceAware, setValidating, setXIncludeAware
  private XMLReader getXMLReader()
    throws LSException 
  { 
    if (reader == null)
      { 
        factory.setNamespaceAware(namespaceAware);
        factory.setValidating(validating);
        factory.setXIncludeAware(xIncludeAware);
        try 
          { 
            SAXParser parser = factory.newSAXParser();
            reader = parser.getXMLReader();
          } 
        catch (ParserConfigurationException e)
          { 
            throw new DomLSException(LSException.PARSE_ERR, e);
          } 
        catch (SAXException e)
          { 
            throw new DomLSException(LSException.PARSE_ERR, e);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newSAXParser, setFeature
   { 
       try 
       { 
          SAXParserFactory spf = SAXParserFactory.newInstance();
          configureParserFactory(spf);
          SAXParser sp = spf.newSAXParser();
          XMLReader xmlReader = sp.getXMLReader();
          SAXSource saxSource = new SAXSource(xmlReader, source);
          return delegate.unmarshal(saxSource);
      } 
      catch (SAXException e)
      { 
         throw new JAXBException(e);
      } 
      catch (ParserConfigurationException e)
      { 
         throw new JAXBException(e);
      } 
   } 
 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newSAXParser, setFeature, setNamespaceAware, setValidating
		// SAX2 namespace-prefixes should be true for either builder 
		setSafeFeature(fty, "http://xml.org/sax/features/namespace-prefixes", true);
 
		// Set SAX2 namespaces feature appropriately 
		setSafeFeature(fty, "http://xml.org/sax/features/namespaces", nsaware);
		fty.setNamespaceAware(nsaware);
 
		setSafeFeature(fty, "http://xml.org/sax/features/validation", validate);
		setSafeFeature(fty, "http://apache.org/xml/features/validation/schema", validate);
		fty.setValidating(validate);
 
		_parser = fty.newSAXParser();
	} 
	private static 
	void setSafeFeature(SAXParserFactory fty, String feature, boolean value) {
		try { 
			fty.setFeature(feature, value);
		} catch (Throwable ex) {
			//IGNORE IT (crimson doesn't support ...validation/schema) 
			if (feature.startsWith("http://xml.org"))

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setNamespaceAware
    @Override 
    @PerThread 
    public SAXParserFactory provide() {
        SAXParserFactory factory = SAXParserFactory.newInstance();
 
        factory.setNamespaceAware(true);
 
        if (!isXmlSecurityDisabled()) { 
            factory = new SecureSaxParserFactory(factory);
        } 
 
        return factory;
    } 
 
    @Override 
    public void dispose(SAXParserFactory instance) {
        //not used 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setFeature, setNamespaceAware, setValidating
	private CmsEntityDeserialization(){ 
		try{ 
			 
			saxParserFactory = SAXParserFactory.newInstance();
			 
			saxParserFactory.setNamespaceAware(true);
			saxParserFactory.setValidating(false);
			 
			saxParserFactory.setFeature("http://apache.org/xml/features/validation/schema",true);
			saxParserFactory.setFeature("http://xml.org/sax/features/validation", true);
			saxParserFactory.setFeature("http://xml.org/sax/features/namespaces",true);
			//saxParserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true); 
			 
			/* 
			 *  
			 * A true value for this feature allows the encoding of the file to be specified as a  
			 * Java encoding name as well as the standard ISO encoding name. Be aware that other  
			 * parsers may not be able to use Java encoding names. If this feature is set to false,  
			 * an error will be generated if Java encoding names are used.   
			 */ 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setFeature, setNamespaceAware, setValidating
		this.entityResolver = entityResolver;
		this.astroboaVersion = astroboaVersion;
 
		//Create SAX Parser 
		parserFactory = SAXParserFactory.newInstance();
		parserFactory.setNamespaceAware(true);
		parserFactory.setValidating(false);
		parserFactory.setFeature("http://apache.org/xml/features/validation/schema",true);
		parserFactory.setFeature("http://xml.org/sax/features/validation", true);
		parserFactory.setFeature("http://xml.org/sax/features/namespaces",true);
		//parserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true); This feature is not recognized 
		 
		/* 
		 *  
		 * A true value for this feature allows the encoding of the file to be specified as a  
		 * Java encoding name as well as the standard ISO encoding name. Be aware that other  
		 * parsers may not be able to use Java encoding names. If this feature is set to false,  
		 * an error will be generated if Java encoding names are used.   
		 */ 
		parserFactory.setFeature("http://apache.org/xml/features/allow-java-encodings",true);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newSAXParser
        qdox.addSourceTree(sourceDir);
    } 
 
    public void load(InputSource inputSource)
            throws ParserConfigurationException, SAXException, IOException { 
        SAXParser saxParser = saxParserFactory.newSAXParser();
        saxParser.parse(inputSource, new DefaultHandler() {
            @Override 
            public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                if (localName.equals("factory")) {
                    String className = attributes.getValue("class");
                    try { 
                        addClass(className);
                    } catch (ClassNotFoundException e) {
                        throw new SAXException("Cannot find Matcher class : " + className);
                    } 
                } 
            } 
        }); 
    } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getFeature, newSAXParser, setFeature, setValidating
            boolean loadExternalDtds) throws ParserConfigurationException, SAXException {
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setNamespaceAware(true);
        parserFactory.setValidating(canUseSchemaValidation && (schema != null));
        if (!loadExternalDtds && canDisableExternalDtds(parserFactory)) {
            parserFactory.setFeature(XERCES_LOAD_EXTERNAL_DTD, false);
        } 
        SAXParser parser = parserFactory.newSAXParser();
 
        if (canUseSchemaValidation && (schema != null)) {
            try { 
                parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                parser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream);
            } catch (SAXNotRecognizedException ex) {
                Message.warn("problem while setting JAXP validating property on SAXParser... " 
                        + "XML validation will not be done (" + ex.getClass().getName() + ": "
                        + ex.getMessage() + ")");
                canUseSchemaValidation = false;
                parserFactory.setValidating(false);
                parser = parserFactory.newSAXParser();

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newSAXParser, setNamespaceAware, setValidating
 
        try { 
 
            // use the factory to create a parser 
            parserFactory = SAXParserFactory.newInstance();
            parserFactory.setValidating(false);
            parserFactory.setNamespaceAware(true);
 
            SAXParser parser = parserFactory.newSAXParser();
            reader = parser.getXMLReader();
 
        } catch (FactoryConfigurationError fce) {
 
            throw new FactoryConfigurationError("No SAX parser defined");
 
        } catch (ParserConfigurationException pce) {
 
            throw new ParserConfigurationException("Unable to configure factory as required");
 
        } catch (SAXException se) {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setFeature, setNamespaceAware
     */ 
    public SAXParserFactory getSAXParserFactory() {
        SAXParserFactory factory = get(SAXParserFactory.class);
        if (factory == null) {
            factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            try { 
                factory.setFeature(
                        XMLConstants.FEATURE_SECURE_PROCESSING, true);
            } catch (ParserConfigurationException e) {
            } catch (SAXNotSupportedException e) {
            } catch (SAXNotRecognizedException e) {
                // TIKA-271: Some XML parsers do not support the 
                // secure-processing feature, even though it's required by 
                // JAXP in Java 5. Ignoring the exception is fine here, as 
                // deployments without this feature are inherently vulnerable 
                // to XML denial-of-service attacks. 
            } 
        } 
        return factory;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 SAXParserFactory Questions & Answers:

See Code Examples for Java 8 SAXParserFactory Methods: