List of usage examples for android.util Xml newPullParser
public static XmlPullParser newPullParser()
From source file:Main.java
public static HashMap<String, String> getServerInfo(InputStream is) throws Exception { HashMap<String, String> hashMap = new HashMap<String, String>(); XmlPullParser parser = Xml.newPullParser(); parser.setInput(is, "UTF-8"); int type = parser.getEventType(); while (type != XmlPullParser.END_DOCUMENT) { switch (type) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: if ("version".equals(parser.getName())) { hashMap.put("version", parser.nextText()); } else if ("mandatory".equals(parser.getName())) { hashMap.put("mandatory", parser.nextText()); } else if ("url".equals(parser.getName())) { hashMap.put("url", parser.nextText()); }//from w ww .j a va 2 s.c o m break; } type = parser.next(); } is.close(); return hashMap; }
From source file:Main.java
/** * Get the xml as a AttributeSet//from w ww .j a va 2s . co m * * @param is XML InputStream * @return AttributeSet representation of the xml stream * @throws XmlPullParserException */ public static AttributeSet getAttributeSet(InputStream is) throws XmlPullParserException { XmlPullParser parser = Xml.newPullParser(); parser.setInput(is, null); AttributeSet set = Xml.asAttributeSet(parser); return set; }
From source file:com.digdream.tasbook.util.IsbnXmlSax.java
public static Book sax(InputStream is) { Book book = null;/*from w w w. jav a 2 s . c om*/ XmlPullParser parser = Xml.newPullParser(); /* * int i = -1; //org.apache.commons.io.output.ByteArrayOutputStream * ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { while * ((i = is.read()) != -1) { baos.write(i); } } catch (IOException e1) { * // TODO Auto-generated catch block e1.printStackTrace(); } String * content = baos.toString(); Log.d("tt", content); */ try { parser.setInput(is, "UTF-8"); int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_TAG: Log.d("test", parser.getName()); if (parser.getName().equals("entry")) { book = new Book(); } else if (parser.getName().equals("link")) { if (parser.getAttributeValue(null, "rel").equals("image")) { book.setImage(parser.getAttributeValue(null, "href")); } eventType = parser.next(); } else if (parser.getName().equals("attribute")) { String attribute = parser.getAttributeValue(0); eventType = parser.next(); if (attribute.equals("title")) { book.setName(parser.getText()); Log.d("TESTTEST", parser.getText()); } else if (attribute.equals("author")) { book.setAuthor(parser.getText()); } else if (attribute.equals("isbn10")) { book.setIsbn10(parser.getText()); } else if (attribute.equals("isbn13")) { book.setIsbn13(parser.getText()); } else if (attribute.equals("publisher")) { book.setPublisher(parser.getText()); } } else if (parser.getName().equals("summary")) { eventType = parser.next(); book.setSummary(parser.getText()); } else if (parser.getName().equals("title")) { if (book != null && book.getName() == null) { Log.d("TESTTEST", parser.getName()); eventType = parser.next(); book.setName(parser.getText()); } } break; case XmlPullParser.END_TAG: break; } eventType = parser.next(); } } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return book; }
From source file:Main.java
/** * Read a HashMap from an InputStream containing XML. The stream can * previously have been written by writeMapXml(). * * @param in The InputStream from which to read. * * @return HashMap The resulting map./*from w w w . j av a2s . c o m*/ * * @see #readListXml * @see #readValueXml * @see #readThisMapXml * #see #writeMapXml */ public static final HashMap readMapXml(InputStream in) throws XmlPullParserException, java.io.IOException { XmlPullParser parser = Xml.newPullParser(); parser.setInput(in, null); return (HashMap) readValueXml(parser, new String[1]); }
From source file:Main.java
/** * Read an ArrayList from an InputStream containing XML. The stream can * previously have been written by writeListXml(). * * @param in The InputStream from which to read. * * @return ArrayList The resulting list. * * @see #readMapXml//from ww w . j av a 2s.co m * @see #readValueXml * @see #readThisListXml * @see #writeListXml */ public static final ArrayList readListXml(InputStream in) throws XmlPullParserException, java.io.IOException { XmlPullParser parser = Xml.newPullParser(); parser.setInput(in, null); return (ArrayList) readValueXml(parser, new String[1]); }
From source file:Main.java
/** * Read a HashSet from an InputStream containing XML. The stream can * previously have been written by writeSetXml(). * * @param in The InputStream from which to read. * * @return HashSet The resulting set.//from w w w .j a v a 2 s . c o m * * @throws XmlPullParserException * @throws java.io.IOException * * @see #readValueXml * @see #readThisSetXml * @see #writeSetXml */ public static final HashSet readSetXml(InputStream in) throws XmlPullParserException, java.io.IOException { XmlPullParser parser = Xml.newPullParser(); parser.setInput(in, null); return (HashSet) readValueXml(parser, new String[1]); }
From source file:cn.ieclipse.pay.wxpay.OrderInfoUtil.java
/** * <xml>/*from w ww . j a v a 2s. c om*/ * <return_code><![CDATA[SUCCESS]]></return_code> * <return_msg><![CDATA[OK]]></return_msg> * <appid><![CDATA[wx2421b1c4370ec43b]]></appid> * <mch_id><![CDATA[10000100]]></mch_id> * <nonce_str><![CDATA[IITRi8Iabbblz1Jc]]></nonce_str> * <sign><![CDATA[7921E432F65EB8ED0CE9755F0E86D72F]]></sign> * <result_code><![CDATA[SUCCESS]]></result_code> * <prepay_id><![CDATA[wx201411101639507cbf6ffd8b0779950874]]></prepay_id> * <trade_type><![CDATA[APP]]></trade_type> * </xml> * ??xml * * @param content ?xml * * @return ?map */ public static Map<String, String> parseXmlResponse(String content) { try { Map<String, String> xml = new HashMap<>(); XmlPullParser parser = Xml.newPullParser(); parser.setInput(new StringReader(content)); int event = parser.getEventType(); while (event != XmlPullParser.END_DOCUMENT) { String nodeName = parser.getName(); switch (event) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: if ("xml".equals(nodeName) == false) { // xml.put(nodeName, parser.nextText()); } break; case XmlPullParser.END_TAG: break; } event = parser.next(); } return xml; } catch (Exception e) { if (Wxpay.DEBUG) { Wxpay.log("xml???" + e.toString()); } } return null; }
From source file:com.connectsdk.service.airplay.PListParser.java
public JSONObject parse(String text) throws XmlPullParserException, IOException, JSONException { XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); Reader stream = new StringReader(text); parser.setInput(stream);/* w ww . j av a 2s . c o m*/ parser.nextTag(); return readPlist(parser); }
From source file:org.openaccessbutton.openaccessbutton.blog.RssParser.java
/** * Parse an InputStream containing the RSS feed. * @param in InputStream containing blog RSS feed * @return List of Posts/*from w ww. j av a2 s .c o m*/ * @throws XmlPullParserException * @throws IOException */ public List<Post> parse(InputStream in) throws XmlPullParserException, IOException { try { XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(in, null); parser.nextTag(); return readFeed(parser); } finally { in.close(); } }
From source file:at.ac.uniklu.mobile.sportal.mensa.MensaParser.java
Mensa parse(URL url) throws IOException, XmlPullParserException { InputStream in = null;/*from w w w .j ava 2 s. c o m*/ Mensa m = null; try { in = url.openStream(); XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(in, null); int type; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { if (type == XmlPullParser.START_TAG && parser.getName().equals("channel")) { m = parseChannel(parser); } } } finally { if (in != null) in.close(); } return m; }