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

This code example shows how to use the following methods:getXMLReader
        PersonHandler parser = new PersonHandler();
        try { 
            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);
8
CodeRank
This code example shows how to use the following methods:getXMLReader, parse, setProperty
              if(schemaValidation == true) {
                   //Using JAXP 1.2 to validate an XML document using an external schema. 
	               if (xmlSchema != null) {
	                 spf = SAXParserFactory.newInstance();
	                 parser= spf.newSAXParser();
                    reader = parser.getXMLReader();
 
                    parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
	                 parser.setProperty(JAXP_SCHEMA_SOURCE, xmlSchema);
 
	                 spf.setNamespaceAware(true);
                    spf.setValidating(true);
                   } 
                   //Using JAXP 1.2 to validate an XML document using the xsi:noNamespaceSchemaLocation value. 
                   else { 
                        spf = SAXParserFactory.newInstance();
 
                        spf.setNamespaceAware(true);
                        spf.setValidating(true);
 

8
CodeRank
This code example shows how to use the following methods:getXMLReader
        } catch (JAXBException ex) {
            throw new ProcessingException(LocalizationMessages.ERROR_WADL_JAXB_CONTEXT(), ex);
        } 
 
        final SAXParser saxParser = saxParserFactory.newSAXParser();
        SAXSource source = new SAXSource(saxParser.getXMLReader(), new InputSource(inputStream));
        final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        final Object result = unmarshaller.unmarshal(source);
        return resultClass.cast(result);
    } 
 
    /** 
     * Return {@code true} if generation of full WADL with 
     * {@link org.glassfish.jersey.server.model.ExtendedResource extended resources} is requested. 
     * 
     * @param uriInfo URI info of the request. 
     * @return {@code true} if full detailed WADL should be generated; false otherwise. 
     */ 
    public static boolean isDetailedWadlRequested(UriInfo uriInfo) {
        final List<String> simple = uriInfo.getQueryParameters().get(DETAILED_WADL_QUERY_PARAM);
8
CodeRank
This code example shows how to use the following methods:parse
            sp.parse(file, handlerBase);
        } 
 
        @Override 
        public void parse(File file, DefaultHandler defaultHandler) throws SAXException, IOException {
            sp.parse(file, defaultHandler);
        } 
 
        @Override 
        @SuppressWarnings("deprecation") 
        public void parse(InputSource inputSource, org.xml.sax.HandlerBase handlerBase) throws SAXException, IOException {
            sp.parse(inputSource, handlerBase);
        } 
 
        @Override 
        public void parse(InputSource inputSource, DefaultHandler defaultHandler) throws SAXException, IOException {
            sp.parse(inputSource, defaultHandler);
        } 
 
        @Override 
7
CodeRank
This code example shows how to use the following methods:getXMLReader
		try { 
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();
 
			/* 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) {
8
CodeRank
This code example shows how to use the following methods:parse
    try{ 
      valList = new ArrayList<Value>();
      DefaultHandler handler = new XMLParser(valList);
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser parser = factory.newSAXParser();
      parser.parse(in, handler);
      vLen = valList.size();
      vIdx = 0;
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    } 
  } 
     
  @Override 
  public byte readByte(String tag) throws IOException {
    Value v = next();
    if (!"ex:i1".equals(v.getType())) {
      throw new IOException("Error deserializing "+tag+".");
    } 
    return Byte.parseByte(v.getValue());
7
CodeRank
This code example shows how to use the following methods:parse
	private Map<String, String> readInfo(File sceneFolder)
			throws ParserConfigurationException, SAXException, IOException { 
		final Map<String, String> values = new HashMap<String, String>();
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		sp.parse(new File(sceneFolder, "Info.plist"), new DefaultHandler() {
			private String key = "", val = "";
			private boolean expectKey;
 
			@Override 
			public void startElement(String uri, String localName,
					String qName, Attributes attributes) throws SAXException {
				expectKey = localName.equalsIgnoreCase("key");
				if (expectKey) {
					key = val = "";
				} 
			} 
 
			@Override 
			public void characters(char[] ch, int start, int length)
7
CodeRank
This code example shows how to use the following methods:getXMLReader
			throws ParserConfigurationException, SAXException, IOException { 
		 
		SAXParserFactory parseFactory = SAXParserFactory.newInstance();
		SAXParser xmlParser = parseFactory.newSAXParser();
 
		XMLReader xmlIn = xmlParser.getXMLReader();
		 
		StreamParser catalogParser = new StreamParser( rootElementsParser );
		xmlIn.setContentHandler(catalogParser);
 
		xmlIn.parse(new InputSource(stream));
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:parse, setProperty
			sf.setNamespaceAware(true);
			sf.setValidating(true);
	 
			// Create parser and let it do XSD-based validation 
			SAXParser sp = sf.newSAXParser();
			sp.setProperty(SCHEMA_LANGUAGE, XML_SCHEMA);
			sp.setProperty(SCHEMA_SOURCE, xsdFile);
 
			// Validate by parsing 
			Validator v = new Validator();
			sp.parse(new File(xmlFile), v);
 
			// Done 
			if (v.error) {
				printFailure(xmlFile);
				return false; 
			} else { 
				printSuccess(xmlFile);
				return true;				 
			} 
7
CodeRank
This code example shows how to use the following methods:getXMLReader, setProperty
      pfactory.setNamespaceAware(true); // Very important!
      // Turn on validation. 
      pfactory.setValidating(true);
      // Get an XMLReader. 
      SAXParser parser = pfactory.newSAXParser();
      XMLReader reader = parser.getXMLReader();
 
      parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
 
      // Instantiate an error handler (see the Handler inner class below) that will report any 
      // errors or warnings that occur as the XMLReader is parsing the XML input. 
 
      reader.setErrorHandler(this);
      SAXSource source = null;
      Transformer t = null;
      // Standard way of creating a transformer from a URL. 
      if (xsltDoc != null){t = tfactory.newTransformer(new StreamSource(xsltDoc));}
      else printUsage(); 
 
      // Specify a SAXSource that takes both an XMLReader and a URL. 
7
CodeRank

Related Java 8 SAXParser Questions & Answers:

See Code Examples for Java 8 SAXParser Methods: