Java 8 XMLReader - 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 XMLReader class.

This code example shows how to use the following methods:parse, setContentHandler
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp;
            sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
 
            xr.setContentHandler(parser);
            StringReader sr = new StringReader(wsContent);
            InputSource is = new InputSource(sr);
            xr.parse(is);
        } catch (ParserConfigurationException e) {
            Log.e(TAG, "ParserConfigurationException", e);
            throw new DataException(e);
        } catch (SAXException e) {
            Log.e(TAG, "SAXException", e);
            throw new DataException(e);
        } catch (IOException e) {
            Log.e(TAG, "IOException", e);
            throw new DataException(e);
        } 
        return parser.mPersonList;
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:parse, setContentHandler
 
			/* Get the XMLReader of the SAXParser we created. */ 
			XMLReader xr = sp.getXMLReader();
			/* Create a new ContentHandler and apply it to the XML-Reader */ 
 
			xr.setContentHandler(responsesHandler);
 
			ByteArrayInputStream tobeparsed = new ByteArrayInputStream(
					responseAsXML.getBytes("UTF-8"));
 
			InputSource is = new InputSource(tobeparsed);
			is.setEncoding("UTF-8");
			xr.parse(is);
 
			/* Parsing has finished. */ 
 
		} catch (FactoryConfigurationError e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:parse, setContentHandler, setErrorHandler, setProperty
 
    public void parse(org.xml.sax.InputSource is) {
    	XMLReader parser = createParser();
    	if(parser == null) return;
    	try { 
    		parser.parse(is);
    	} catch (SAXException e) {
			ModelPlugin.getPluginLog().logError(e);
    	} catch (IOException e) {
			ModelPlugin.getPluginLog().logError(e);
    	} 
	} 
    
    XMLReader newInstance() throws SAXException {
    	try { 
    	    return (XMLReader) ModelPlugin.getDefault().getBundle().loadClass(DEFAULT_SAX_PARSER_CLASS_NAME).newInstance();
    	} catch (ClassNotFoundException e1) {
    	    throw new SAXException("SAX2 driver class " + DEFAULT_SAX_PARSER_CLASS_NAME +
    				   " not found", e1);
    	} catch (IllegalAccessException e2) {

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:parse, setContentHandler
 
	@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);
	} 
 
	@Test
	public void contentHandlerElement() throws Exception {
		Element rootElement = result.createElementNS("namespace", "root");
		result.appendChild(rootElement);
		handler = new DomContentHandler(rootElement);
		expected = documentBuilder.parse(new InputSource(new StringReader(XML_2_EXPECTED)));
		xmlReader.setContentHandler(handler);
		xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET)));
		assertXMLEqual("Invalid result", expected, result);
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setProperty
		} 
	} 
 
	@Override 
	protected void onSetReceiver() { 
		saxReader.setContentHandler(getReceiver());
		saxReader.setDTDHandler(getReceiver());
		saxReader.setEntityResolver(getReceiver());
		saxReader.setErrorHandler(getReceiver());
		try { 
			saxReader.setProperty(SAX_PROPERTY_LEXICAL_HANDLER, getReceiver());
		} catch (SAXNotRecognizedException e) {
			throw new MetafactureException(e);
		} catch (SAXNotSupportedException e) {
			throw new MetafactureException(e);
		} 
	} 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:parse, setContentHandler, setFeature
        try { 
            SAXParserFactory saxfactory = SAXParserFactory.newInstance();
            saxfactory.setValidating(false);
            SAXParser parser = saxfactory.newSAXParser();
            xmlReader = parser.getXMLReader();
            xmlReader.setContentHandler(this);
            xmlReader.setFeature("http://xml.org/sax/features/namespaces",
                                 false); 
            xmlReader
                    .setFeature("http://xml.org/sax/features/namespace-prefixes",
                                false); 
        } catch (Exception e) {
            throw new RepositoryConfigurationException("Internal SAX error while " 
                    + "preparing for Method Map datastream parsing: " 
                    + e.getMessage());
        } 
        try { 
            xmlReader.parse(new InputSource(in));
        } catch (Exception e) {
            throw new ObjectIntegrityException("Error parsing Method Map datastream" 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:parse, setContentHandler
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 XMLReader Questions & Answers:

See Code Examples for Java 8 XMLReader Methods: