Best code examples for Java 8 XMLReader class (org.xml.sax.XMLReader)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 XMLReader class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 XMLReader examples from Open Source projects
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;
Full Snippet Info
8
CodeRank
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();
Full Snippet Info
8
CodeRank
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) {
Full Snippet Info
8
CodeRank
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
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);
 
Full Snippet Info
7
CodeRank
Related Java 8 XMLReader Questions & Answers:
See Code Examples for Java 8 XMLReader Methods: