XMLReader parse - 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 parse 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:
 
			final XMLReader xr = sp.getXMLReader();
			final TSXParser tsxParser = new TSXParser(this.mAssetManager, this.mTextureManager, this.mTextureOptions, pFirstGlobalTileID);
			xr.setContentHandler(tsxParser);
 
			xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
 
			return tsxParser.getTMXTileSet();
		} catch (final SAXException e) {
			throw new TSXLoadException(e);
		} catch (final ParserConfigurationException pe) {
			/* Doesn't happen. */ 
			return null; 
		} catch (final IOException e) {
			throw new TSXLoadException(e);
		} 
	} 
 
	// =========================================================== 
	// Inner and Anonymous Classes 
8
CodeRank
This code example shows how to use the following methods:
 
   public static Document parse(String html) throws SAXException, IOException {
      XMLReader saxReader = getParser();
      GwtXmlContentHandler contentHandler = new GwtXmlContentHandler();
      saxReader.setContentHandler(contentHandler);
      saxReader.parse(new InputSource(new StringReader(html)));
 
      return contentHandler.getParsedDocument();
   } 
 
   private static XMLReader getParser() {
      if (PARSER == null) {
         PARSER = XmlUtils.newXMLReader();
      } 
 
      return PARSER;
 
   } 
 
} 
8
CodeRank
This code example shows how to use the following methods:
 
			final XMLReader xr = sp.getXMLReader();
			final TexturePackParser texturePackerParser = new AssetTexturePackParser(this.mTextureManager, pAssetManager, this.mAssetBasePath);
			xr.setContentHandler(texturePackerParser);
 
			xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
 
			return texturePackerParser.getTexturePack();
		} catch (final SAXException e) {
			throw new TexturePackParseException(e);
		} catch (final ParserConfigurationException pe) {
			/* Doesn't happen. */ 
			return null; 
		} catch (final IOException e) {
			throw new TexturePackParseException(e);
		} finally { 
			StreamUtils.close(pInputStream);
		} 
	} 
 
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:
			/* Create a new ContentHandler and apply it to the XML-Reader*/ 
			final AASParser aasParser = new AASParser();
			xr.setContentHandler(aasParser);
 
			/* Parse the xml-data from our URL. */ 
			xr.parse(new InputSource(new BufferedInputStream(response.getEntity().getContent())));
 
			/* The Handler now provides the parsed data to us. */ 
			return aasParser.getASSResponse();
		} 
	} 
 
	// =========================================================== 
	// Inner and Anonymous Classes 
	// =========================================================== 
} 
8
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

Related XMLReader parse Questions & Answers:

parse Method Overview
Parse an XML document.
See Code Examples for other Java 8 XMLReader Methods: