List of usage examples for javax.xml.parsers SAXParserFactory newSAXParser
public abstract SAXParser newSAXParser() throws ParserConfigurationException, SAXException;
From source file:org.transdroid.search.RssFeedSearch.PretomeAdapter.java
@Override protected RssParser getRssParser(final String url) { return new RssParser(url) { @Override//from www . ja va 2 s.com public void parse() throws ParserConfigurationException, SAXException, IOException { HttpClient httpclient = initialise(); HttpResponse result = httpclient.execute(new HttpGet(url)); //FileInputStream urlInputStream = new FileInputStream("/sdcard/rsstest2.txt"); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); InputSource is = new InputSource(); // Pretome supplies UTF-8 compatible character data yet incorrectly defined a windows-1251 encode: override is.setEncoding("UTF-8"); is.setCharacterStream(new InputStreamReader(result.getEntity().getContent())); sp.parse(is, this); } }; }
From source file:de.l3s.souza.search.DBpediaLookupClient.java
public DBpediaLookupClient(String query) throws Exception { this.query = query; //System.out.println("\n query: " + query); HttpClient client = new HttpClient(); String query2 = query.replaceAll(" ", "+"); // URLEncoder.encode(query, "utf-8"); //System.out.println("\n query2: " + query2); HttpMethod method = new GetMethod( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + query2); try {//from w ww. j a v a 2 s .co m // System.out.println("\n method: " + method.getURI()); client.executeMethod(method); // System.out.println(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.err.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.err.println("Unable to connect to lookup.dbpedia.org"); } method.releaseConnection(); }
From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java
public static ListSubscriptionParser getSubscriptionDataFromString(String res) { //System.out.println("Starting parsing: res is:" + res); javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl(); javax.xml.parsers.SAXParser saxParser; ListSubscriptionParser pl = new ListSubscriptionParser(); try {/*from w w w . j a v a 2s .c o m*/ saxParser = fac.newSAXParser(); saxParser.parse(new ByteArrayInputStream(res.getBytes()), pl); } catch (Exception ex) { logger.error("Exception parsing", ex); } return pl; }
From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java
public static Vector<String> getArnsFromString(String res) { //System.out.println("Starting parsing: res is:" + res); javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl(); javax.xml.parsers.SAXParser saxParser; ListTopicsResponseParser pl = new ListTopicsResponseParser(); try {//w ww . ja v a2s .c om saxParser = fac.newSAXParser(); saxParser.parse(new ByteArrayInputStream(res.getBytes()), pl); } catch (Exception ex) { logger.error("Exception parsing", ex); } return pl.getArns(); }
From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java
public static String getArnFromString(String res) { javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl(); javax.xml.parsers.SAXParser saxParser; CreateTopicResponseParser p = new CreateTopicResponseParser(); try {/*from w w w . j a v a 2 s. co m*/ saxParser = fac.newSAXParser(); saxParser.parse(new ByteArrayInputStream(res.getBytes()), p); } catch (Exception ex) { logger.error("Exception parsing", ex); } String arn = p.getTopicArn(); return arn; }
From source file:com.vionto.vithesaurus.wikipedia.CommonsAudioDumper.java
private void run(InputStream is) throws IOException, SAXException, ParserConfigurationException { CommonsPageHandler handler = new CommonsPageHandler(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);//from w w w . j a va 2s. co m System.out.println("SET NAMES utf8;"); saxParser.parse(is, handler); System.err.println("Exported: " + handler.exported); System.err.println("Skipped: " + handler.skipped); System.err.println("Skipped " + handler.noLicense + " because of missing/undetected license"); }
From source file:com.aurel.track.exchange.track.importer.ImporterFieldParser.java
public List<ISerializableLabelBean> parse(File xml) { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try {//from w w w . ja v a 2s. c o m //get a new instance of parser SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs LOGGER.debug("Field parser started..."); sp.parse(xml, this); LOGGER.debug("Field parser done..."); return fieldBeans; } catch (SAXException se) { LOGGER.error(ExceptionUtils.getStackTrace(se)); } catch (ParserConfigurationException pce) { LOGGER.error(ExceptionUtils.getStackTrace(pce)); } catch (IOException ie) { LOGGER.error(ExceptionUtils.getStackTrace(ie)); } return null; }
From source file:com.inferiorhumanorgans.WayToGo.Agency.BART.Prediction.XMLTask.java
@Override protected Void doInBackground(BARTAgency... someAgencies) { super.doInBackground(someAgencies); theListener.startPredictionFetch();//w w w. jav a 2 s . c om Log.d(LOG_NAME, "Trying to get Predictions."); InputStream content = null; ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient hc = new DefaultHttpClient(connman, params); String theURL = BART_URL + BARTAgency.API_KEY + "&orig=" + theStationTag; Log.i(LOG_NAME, "Fetching from: " + theURL); HttpGet getRequest = new HttpGet(theURL); try { content = hc.execute(getRequest).getEntity().getContent(); } catch (ClientProtocolException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } Log.d(LOG_NAME, "Put the BART predictions in the background."); try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(dataHandler); xr.parse(new InputSource(content)); } catch (ParserConfigurationException pce) { Log.e(LOG_NAME + " SAX XML", "sax parse error", pce); } catch (AbortXMLParsingException abrt) { Log.d(LOG_NAME + " AsyncXML", "Cancelled!!!!!"); } catch (SAXException se) { Log.e(LOG_NAME + " SAX XML", "sax error", se); } catch (IOException ioe) { Log.e(LOG_NAME + " SAX XML", "sax parse io error", ioe); } Log.d(LOG_NAME + " SAX XML", "Done parsing BART station XML"); return null; }
From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java
public static SubscriptionAttributeParser getSubscriptionAttributesFromString(String res) { javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl(); javax.xml.parsers.SAXParser saxParser; SubscriptionAttributeParser p = new SubscriptionAttributeParser(); try {// ww w . jav a2 s. c o m saxParser = fac.newSAXParser(); saxParser.parse(new ByteArrayInputStream(res.getBytes()), p); } catch (Exception ex) { logger.error("Exception parsing", ex); } return p; }
From source file:com.entertailion.android.overlaynews.rss.RssHandler.java
public RssFeed getFeed(String data) { feed = null;//from w ww .ja v a 2 s . c o m try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); InputSource inStream = new org.xml.sax.InputSource(); inStream.setCharacterStream(new StringReader(data)); xr.setContentHandler(this); feed = new RssFeed(); xr.parse(inStream); xr = null; sp = null; spf = null; } catch (Exception e) { Log.e(LOG_CAT, "getFeed", e); } return feed; }