XMLReader setContentHandler - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for XMLReader setContentHandler method.

This code example shows how to use the following methods:parse, setContentHandler, setFeature, setProperty
 
	@Test
	public void namespacePrefixes() throws Exception {
		StringWriter stringWriter = new StringWriter();
		AbstractStaxHandler handler = createStaxHandler(new StreamResult(stringWriter));
		xmlReader.setContentHandler(handler);
		xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
 
		xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
		xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
 
		xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
 
		assertXMLEqual(COMPLEX_XML, stringWriter.toString());
	} 
 
	@Test
	public void noNamespacePrefixesDom() throws Exception {
		DocumentBuilderFactory documentBuilderFactory =
				DocumentBuilderFactory.newInstance();
8
CodeRank
This code example shows how to use the following methods:parse, setContentHandler
        spf.setValidating(false);
        try { 
            final SAXParser saxParser = spf.newSAXParser();
            final XMLReader xmlReader = saxParser.getXMLReader();
            final CustomAttributeHandler handler = new CustomAttributeHandler();
            xmlReader.setContentHandler(handler);
            xmlReader.parse(new InputSource(new StringReader(xml)));
            return handler.getAttributes();
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
            return Collections.emptyMap();
        } 
    } 
 
    /** 
     * Template method if additional custom parsing (such as Proxying) needs to be done. 
     * 
     * @param response the original response from the CAS server. 
     * @param assertion the partially constructed assertion. 
     * @throws TicketValidationException if there is a problem constructing the Assertion. 
7
CodeRank
This code example shows how to use the following methods:parse, setContentHandler, setFeature
		xmlReader = XMLReaderFactory.createXMLReader();
	} 
 
	@Test
	public void contentHandlerDocumentNamespacePrefixes() throws Exception {
		xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
		handler = new DomContentHandler(result);
		expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
		xmlReader.setContentHandler(handler);
		xmlReader.parse(new InputSource(new StringReader(XML_1)));
		assertXMLEqual("Invalid result", expected, result);
	} 
 
	@Test
	public void contentHandlerDocumentNoNamespacePrefixes() throws Exception {
		handler = new DomContentHandler(result);
		expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
		xmlReader.setContentHandler(handler);
		xmlReader.parse(new InputSource(new StringReader(XML_1)));
		assertXMLEqual("Invalid result", expected, result);
7
CodeRank
This code example shows how to use the following methods:parse, setContentHandler
        System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver"); 
 
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		XMLReader xr = sp.getXMLReader();
		xr.setContentHandler(this);
		xr.parse(new InputSource(mXMLUrl.openStream()));
 
        AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(mContext, dest);
        try { 
            CardDao cardDao = helper.getCardDao();
            cardDao.createCards(cardList);
        } finally { 
            AnyMemoDBOpenHelperManager.releaseHelper(helper);
        } 
    } 
	 
	public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException{
        if(localName.equals("Question")){
            characterBuf = new StringBuffer();
7
CodeRank
This code example shows how to use the following methods:parse, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler
        try { 
            final SAXParser parser = getParser();
            final XMLReader reader = parser.getXMLReader();
 
            try { 
                reader.setFeature("http://xml.org/sax/features/validation", isValidateDTD());
            } 
            catch (SAXException se) {
                Log.debug("The XMLReader will not validate the xml document.", se);
            } 
            final FrontendDefaultHandler handler = createDefaultHandler(contentBase);
            configureReader(reader, handler);
            try { 
                reader.setContentHandler(handler);
                reader.setDTDHandler(handler);
                if (getEntityResolver() != null) { 
                    reader.setEntityResolver(getEntityResolver());
                } 
                reader.setErrorHandler(handler);
                reader.parse(input);

7
CodeRank
This code example shows how to use the following methods:parse, setContentHandler
 
        try { 
	        SAXParserFactory spf = SAXParserFactory.newInstance();
	        SAXParser sp = spf.newSAXParser();
	        XMLReader xr = sp.getXMLReader();
	        xr.setContentHandler(this);
	        xr.parse(inputSource);
	    } catch (IOException e) {
	        Log.e(TAG, e.toString());
	    } catch (SAXException e) {
	        Log.e(TAG, e.toString());
	    } catch (ParserConfigurationException e) {
	        Log.e(TAG, e.toString());
	    } 
 
		return getContent(); 
	} 
	 
    public void characters(char ch[], int start, int length) {
    	stringBuilder.append(ch, start, length);
7
CodeRank
This code example shows how to use the following methods:parse, setContentHandler, setEntityResolver, setErrorHandler
		 
		 
		try { 
 
			xmlReader=XMLUtil.createXMLReader(saxParser);
			xmlReader.setContentHandler(this);
			xmlReader.setErrorHandler(this);
			xmlReader.setEntityResolver(new FunctionLibEntityResolver());
			xmlReader.parse(is);
		} catch (IOException e) {
			 
			throw new FunctionLibException("IO Exception: "+e.getMessage());
		} catch (SAXException e) {
			throw new FunctionLibException("SaxException: "+e.getMessage());
		} 
		 
    } 
	     
	/** 
	 * Geerbte Methode von org.xml.sax.ContentHandler,  
6
CodeRank
This code example shows how to use the following methods:parse, setContentHandler
			final SAXParserFactory spf = SAXParserFactory.newInstance();
			final SAXParser sp = spf.newSAXParser();
 
			final XMLReader xr = sp.getXMLReader();
			final PXParser pxParser = new PXParser(this.mContext, this.mTextureManager, this.mTextureOptions);
			xr.setContentHandler(pxParser);
 
			xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
 
			return pxParser.getPXSystem();
		} catch (final SAXException e) {
			throw new PXLoadException(e);
		} catch (final ParserConfigurationException pe) {
			/* Doesn't happen. */ 
			return null; 
		} catch (final IOException e) {
			throw new PXLoadException(e);
		} 
	} 
 
7
CodeRank
This code example shows how to use the following methods:parse, setContentHandler, setFeature
      final SAXParser parser = factory.newSAXParser();
      final XMLReader reader = parser.getXMLReader();
 
      try 
      { 
        reader.setFeature("http://xml.org/sax/features/xmlns-uris", false);
      } 
      catch (SAXException e)
      { 
        // ignored 
      } 
      try 
      { 
        reader.setFeature("http://xml.org/sax/features/namespaces", false);
        reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
      } 
      catch (final SAXException e)
      { 
        logger.warn("No Namespace features will be available. (Yes, this is serious)", e);
      } 

7
CodeRank
This code example shows how to use the following methods:setContentHandler, setErrorHandler, setProperty
        } catch (SAXException e) {
        	ModelPlugin.getPluginLog().logError("default parser failed: " + e.getMessage());        	
        	return null; 
        } 
 
        SAXValidator.setFeature(parserInstance, NAMESPACES_FEATURE_ID, false);
        SAXValidator.setFeature(parserInstance, NAMESPACE_PREFIXES_FEATURE_ID, false);
        SAXValidator.setFeature(parserInstance, VALIDATION_FEATURE_ID, false);
        SAXValidator.setFeature(parserInstance, VALIDATION_SCHEMA_FEATURE_ID, false);
        SAXValidator.setFeature(parserInstance, VALIDATION_SCHEMA_CHECKING_FEATURE_ID, false);
        SAXValidator.setFeature(parserInstance, VALIDATION_DYNAMIC_FEATURE_ID, false);
        SAXValidator.setFeature(parserInstance, FATAL_ERROR_PROCESSING_FEATURE_ID, false);
 
        try { 
        	if(MetaLibLoader.validateMetaXML) {
        		parserInstance.setProperty(ENTITY_RESOLVER_PROPERTY_ID, new XMLEntityResolverImpl());
        	} else { 
        		parserInstance.setProperty(ENTITY_RESOLVER_PROPERTY_ID, new EmptyHandler());
        	} 
        } catch (SAXException e1) {

7
CodeRank

Related XMLReader setContentHandler Questions & Answers:

setContentHandler Method Overview
Allow an application to register a content event handler.
See Code Examples for other Java 8 XMLReader Methods: