Java Code Examples for org.xmlpull.v1.XmlPullParser#setInput()

The following examples show how to use org.xmlpull.v1.XmlPullParser#setInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreeOtpImporter.java    From Aegis with GNU General Public License v3.0 6 votes vote down vote up
@Override
public State read(FileReader reader) throws DatabaseImporterException {
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(reader.getStream(), null);
        parser.nextTag();

        List<JSONObject> entries = new ArrayList<>();
        for (PreferenceParser.XmlEntry entry : PreferenceParser.parse(parser)) {
            if (!entry.Name.equals("tokenOrder")) {
                entries.add(new JSONObject(entry.Value));
            }
        }
        return new State(entries);
    } catch (XmlPullParserException | IOException | JSONException e) {
        throw new DatabaseImporterException(e);
    }
}
 
Example 2
Source File: GenericXmlListTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * The purpose is to have a Collection of {@link java.lang.reflect.ParameterizedType} elements.
 */
@Test
public void testParseToCollectionOfArrayMaps() throws Exception {
  CollectionOfArrayMapsTypeGeneric xml = new CollectionOfArrayMapsTypeGeneric();
  XmlPullParser parser = Xml.createParser();
  parser.setInput(new StringReader(COLLECTION_OF_ARRAY));
  XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
  Xml.parseElement(parser, xml, namespaceDictionary, null);
  // check type
  assertEquals(2, xml.rep.size());
  assertEquals("a", xml.rep.toArray(new ArrayMap[] {})[0].getValue(0));
  assertEquals("a", xml.rep.toArray(new ArrayMap[] {})[0].getKey(0));
  assertEquals("b", xml.rep.toArray(new ArrayMap[] {})[0].getValue(1));
  assertEquals("b", xml.rep.toArray(new ArrayMap[] {})[0].getKey(1));
  assertEquals("c", xml.rep.toArray(new ArrayMap[] {})[1].getValue(0));
  assertEquals("c", xml.rep.toArray(new ArrayMap[] {})[1].getKey(0));
  assertEquals("d", xml.rep.toArray(new ArrayMap[] {})[1].getValue(1));
  assertEquals("d", xml.rep.toArray(new ArrayMap[] {})[1].getKey(1));
  // serialize
  XmlSerializer serializer = Xml.createSerializer();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  serializer.setOutput(out, "UTF-8");
  namespaceDictionary.serialize(serializer, "any", xml);
  assertEquals(COLLECTION_OF_ARRAY, out.toString());
}
 
Example 3
Source File: OverlayManagerSettings.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static void restore(@NonNull final ArrayList<SettingsItem> table,
        @NonNull final InputStream is) throws IOException, XmlPullParserException {

    try (InputStreamReader reader = new InputStreamReader(is)) {
        table.clear();
        final XmlPullParser parser = Xml.newPullParser();
        parser.setInput(reader);
        XmlUtils.beginDocument(parser, TAG_OVERLAYS);
        int version = XmlUtils.readIntAttribute(parser, ATTR_VERSION);
        if (version != CURRENT_VERSION) {
            upgrade(version);
        }
        int depth = parser.getDepth();

        while (XmlUtils.nextElementWithin(parser, depth)) {
            switch (parser.getName()) {
                case TAG_ITEM:
                    final SettingsItem item = restoreRow(parser, depth + 1);
                    table.add(item);
                    break;
            }
        }
    }
}
 
Example 4
Source File: BluetoothXmlParser.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
public Characteristic parseCharacteristic(XmlPullParser parser, String fileName) throws XmlPullParserException,
        IOException {
    InputStream in = null;
    in = appContext.getAssets().open(fileName);
    parser.setInput(in, null);
    parser.nextTag();

    UUID uuid = readUUID(parser);
    String type = readType(parser);

    Characteristic charact = readCharacteristic(parser);
    charact.setUuid(uuid);
    charact.setType(type);

    in.close();
    return charact;
}
 
Example 5
Source File: XmlTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * The purpose of this tests it to test the {@link Key} Annotation for mapping of elements and
 * attributes. All elements/attributes are matched.
 */
@Test
public void testParseToAnyType() throws Exception {
  AnyType xml = new AnyType();
  XmlPullParser parser = Xml.createParser();
  parser.setInput(new StringReader(ANY_TYPE_XML));
  XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
  Xml.parseElement(parser, xml, namespaceDictionary, null);
  assertTrue(xml.attr instanceof String);
  assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList<?>);
  assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList<?>);
  assertNotNull(xml.value);
  assertTrue(xml.value.content instanceof String);
  // serialize
  XmlSerializer serializer = Xml.createSerializer();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  serializer.setOutput(out, "UTF-8");
  namespaceDictionary.serialize(serializer, "any", xml);
  assertEquals(ANY_TYPE_XML, out.toString());
}
 
Example 6
Source File: MultiKindFeedParser.java    From google-api-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the given HTTP response using the given feed class and entry classes.
 *
 * @param <T> feed type
 * @param <E> entry type
 * @param response HTTP response
 * @param namespaceDictionary XML namespace dictionary
 * @param feedClass feed class
 * @param entryClasses entry class
 * @return Atom multi-kind feed pull parser
 * @throws IOException I/O exception
 * @throws XmlPullParserException XML pull parser exception
 */
public static <T, E> MultiKindFeedParser<T> create(HttpResponse response,
    XmlNamespaceDictionary namespaceDictionary, Class<T> feedClass, Class<E>... entryClasses)
    throws IOException, XmlPullParserException {
  InputStream content = response.getContent();
  try {
    Atom.checkContentType(response.getContentType());
    XmlPullParser parser = Xml.createParser();
    parser.setInput(content, null);
    MultiKindFeedParser<T> result =
        new MultiKindFeedParser<T>(namespaceDictionary, parser, content, feedClass);
    result.setEntryClasses(entryClasses);
    return result;
  } finally {
    content.close();
  }
}
 
Example 7
Source File: GradleDependencyEntity.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * xml解析为对象
 *
 * @param text
 * @return
 */
public static GradleDependencyEntity parse(String text) {
    GradleDependencyEntity entity = new GradleDependencyEntity();
    XmlPullParserFactory f = null;
    try {
        f = XmlPullParserFactory.newInstance();
        f.setNamespaceAware(true);
        XmlPullParser xmlPullParser = f.newPullParser();
        xmlPullParser.setInput(new InputStreamReader(new ByteArrayInputStream(text.getBytes())));
        int eventType = xmlPullParser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_DOCUMENT) {

            } else if (eventType == XmlPullParser.START_TAG) {
                String name = xmlPullParser.getName();
                if (name.equals("groupId")) {
                    entity.setGroupId(xmlPullParser.nextText());
                } else if (name.equals("artifactId")) {
                    entity.setArtifactId(xmlPullParser.nextText());
                } else if (name.equals("version")) {
                    String version = xmlPullParser.nextText();
                    entity.setVersion(version);
                } else if (name.equals("lastUpdated")) {
                    entity.setUpdateTime(xmlPullParser.nextText());
                }
            } else if (eventType == XmlPullParser.END_TAG) {

            } else if (eventType == XmlPullParser.TEXT) {

            }
            eventType = xmlPullParser.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return entity;
}
 
Example 8
Source File: PListParser.java    From Connect-SDK-Android-Core with Apache License 2.0 5 votes vote down vote up
public JSONObject parse(InputStream in) throws XmlPullParserException, IOException,
        JSONException {
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();
        return readPlist(parser);
    } finally {
        in.close();
    }
}
 
Example 9
Source File: ToolsHelper.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected XmlPullParser loadXml(InputStream stream) throws XmlPullParserException, IOException {
	BufferedInputStream input = new BufferedInputStream(stream);
	XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
	factory.setNamespaceAware(true);
	XmlPullParser xpp = factory.newPullParser();
	xpp.setInput(input, "UTF-8");
	xpp.next();
	return xpp;
}
 
Example 10
Source File: CoordinateReaderOsmAnd.java    From brouter with MIT License 4 votes vote down vote up
private void _readNogoLine( File file ) throws Exception
{
  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  factory.setNamespaceAware(false);
  XmlPullParser xpp = factory.newPullParser();

  xpp.setInput(new FileReader(file));
  OsmNogoPolygon nogo = new OsmNogoPolygon(false);
  int eventType = xpp.getEventType();
  int numSeg = 0;
  while (eventType != XmlPullParser.END_DOCUMENT) {
    switch(eventType) {
    case XmlPullParser.START_TAG: {
      if (xpp.getName().equals("trkpt")) {
        final String lon = xpp.getAttributeValue(null,"lon");
        final String lat = xpp.getAttributeValue(null,"lat");
        if (lon != null && lat != null) {
          nogo.addVertex(
              (int)( ( Double.parseDouble(lon) + 180. ) *1000000. + 0.5),
              (int)( ( Double.parseDouble(lat) +  90. ) *1000000. + 0.5));
        }
      }
      break;
    }
    case XmlPullParser.END_TAG: {
      if (xpp.getName().equals("trkseg")) {
        nogo.calcBoundingCircle();
        final String name = file.getName();
        nogo.name = name.substring(0, name.length()-4);
        if (numSeg > 0)
        {
          nogo.name += Integer.toString(numSeg+1);
        }
        numSeg++;
        checkAddPoint( "(one-for-all)", nogo );
      }
      break;
    }
    }
    eventType = xpp.next();
  }
}
 
Example 11
Source File: XMLParser.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
static public ArrayList<VolumeList> getVolumeList(String xml) {
	try {
		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		XmlPullParser xmlPullParser = factory.newPullParser();
		ArrayList<VolumeList> l = null;
		VolumeList vl = null;
		ChapterInfo ci = null;
		xmlPullParser.setInput(new StringReader(xml));
		int eventType = xmlPullParser.getEventType();

		while (eventType != XmlPullParser.END_DOCUMENT) {
			switch (eventType) {
			case XmlPullParser.START_DOCUMENT:
				l = new ArrayList<VolumeList>();
				break;

			case XmlPullParser.START_TAG:

				if ("volume".equals(xmlPullParser.getName())) {
					vl = new VolumeList();
					vl.chapterList = new ArrayList<ChapterInfo>();
					vl.vid = new Integer(xmlPullParser.getAttributeValue(0));

					// Here the returned text has some format error
					// And I will handle them then
					Log.v("MewX-XML", "+ " + vl.vid + "; ");
				} else if ("chapter".equals(xmlPullParser.getName())) {
					ci = new ChapterInfo();
					ci.cid = new Integer(xmlPullParser.getAttributeValue(0));
					ci.chapterName = xmlPullParser.nextText();
					Log.v("MewX-XML", ci.cid + "; " + ci.chapterName);
					vl.chapterList.add(ci);
					ci = null;
				}
				break;

			case XmlPullParser.END_TAG:
				if ("volume".equals(xmlPullParser.getName())) {
					l.add(vl);
					vl = null;
				}
				break;
			}
			eventType = xmlPullParser.next();
		}

		/** Handle the rest problem */
		// Problem like this:
		// <volume vid="41748"><![CDATA[第一卷 告白于苍刻之夜]]>
		// <chapter cid="41749"><![CDATA[序章]]></chapter>
		int currentIndex = 0;
		for (int i = 0; i < l.size(); i++) {
			currentIndex = xml.indexOf("volume", currentIndex);
			if (currentIndex != -1) {
				currentIndex = xml.indexOf("CDATA[", currentIndex);
				if (xml.indexOf("volume", currentIndex) != -1) {
					int beg = currentIndex + 6;
					int end = xml.indexOf("]]", currentIndex);

					if (end != -1) {
						l.get(i).volumeName = xml.substring(beg, end);
						Log.v("MewX-XML", "+ " + l.get(i).volumeName + "; ");
						currentIndex = end + 1;
					} else
						break;

				} else
					break;
			} else
				break;
		}

		return l;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
Example 12
Source File: SuntimesThemeXML.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param context a context used to access resources
 * @param in a BufferedInputStream that is open and ready to be read from
 * @return an array of SuntimesTheme
 * @throws IOException if failed to read from in
 */
@Override
public SuntimesTheme[] read(Context context, BufferedInputStream in) throws IOException
{
    signalImportStarted();
    SuntimesTheme themes[] = new SuntimesTheme[0];
    boolean noErrors = true;
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);

        XmlPullParser parser = factory.newPullParser();
        parser.setInput(in, null);

        int parseEvent = parser.getEventType();
        while (parseEvent != XmlPullParser.END_DOCUMENT)
        {
            String tag = parser.getName();
            switch (parseEvent)
            {
                case XmlPullParser.START_TAG:
                    if (tag.equalsIgnoreCase(KEY_THEMES))
                    {
                        //Log.d("SuntimesThemeXML.read", "START_TAG: " + tag);
                        themes = readThemes(parser);
                    } else Log.w("SuntimesThemeXML.read", "unrecognized: " + tag);
                    break;
            }
            parseEvent = parser.next();
        }
        //Log.d("SuntimesThemeXML.read", "done");

    } catch (XmlPullParserException e1) {
        Log.e("SuntimesThemeXML.read", "Failed to parse themes :: " + e1);
        noErrors = false;

    } catch (IOException e2) {
        Log.e("SuntimesThemeXML.read", "Failed to read themes :: " + e2);
        noErrors = false;
    }
    signalImportFinished(noErrors && themes.length > 0);
    return themes;
}
 
Example 13
Source File: XMLParser.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
static public NovelFullInfo getNovelFullInfo(String xml) {
	try {
		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		XmlPullParser xmlPullParser = factory.newPullParser();
		NovelFullInfo nfi = null;
		xmlPullParser.setInput(new StringReader(xml));
		int eventType = xmlPullParser.getEventType();

		while (eventType != XmlPullParser.END_DOCUMENT) {
			switch (eventType) {
			case XmlPullParser.START_DOCUMENT:
				break;

			case XmlPullParser.START_TAG:

				if ("metadata".equals(xmlPullParser.getName())) {
					nfi = new NovelFullInfo();
				} else if ("data".equals(xmlPullParser.getName())) {
					if ("Title".equals(xmlPullParser.getAttributeValue(0))) {
						nfi.aid = new Integer(
								xmlPullParser.getAttributeValue(1));
						nfi.title = xmlPullParser.nextText();
					} else if ("Author".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.author = xmlPullParser.getAttributeValue(1);
					} else if ("DayHitsCount".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.dayHitsCount = new Integer(xmlPullParser.getAttributeValue(1));
					} else if ("TotalHitsCount".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.totalHitsCount = new Integer(xmlPullParser.getAttributeValue(1));
					} else if ("PushCount".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.pushCount = new Integer(xmlPullParser.getAttributeValue(1));
					} else if ("FavCount".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.favCount = new Integer(xmlPullParser.getAttributeValue(1));
					} else if ("PressId".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.pressId = xmlPullParser.getAttributeValue(1);
					} else if ("BookStatus".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.bookStatus = xmlPullParser.getAttributeValue(1);
					} else if ("BookLength".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.bookLength = new Integer(xmlPullParser.getAttributeValue(1));
					} else if ("LastUpdate".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.lastUpdate = xmlPullParser.getAttributeValue(1);
					} else if ("LatestSection".equals(xmlPullParser
							.getAttributeValue(0))) {
						nfi.latestSectionCid = new Integer(
								xmlPullParser.getAttributeValue(1));
						nfi.latestSectionName=xmlPullParser.nextText();
					}
				}
				break;
			}
			eventType = xmlPullParser.next();
		}
		return nfi;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
Example 14
Source File: CssStyle.java    From 4pdaClient-plus with Apache License 2.0 4 votes vote down vote up
private static CssStyle parseStyle(CssStyle cssStyle, InputStream in) throws XmlPullParserException, IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
    parser.setInput(in, null);


    int eventType = parser.getEventType();
    if (eventType == XmlPullParser.END_DOCUMENT)
        return null;

    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        eventType = parser.getEventType();

        if (eventType == XmlPullParser.START_TAG) {
            String name = parser.getName().toLowerCase();
            if (name.equals("title")) {
                parser.next();
                eventType = parser.getEventType();
                if (eventType == XmlPullParser.TEXT)
                    cssStyle.Title = parser.getText();
            } else if (name.equals("version")) {
                parser.next();
                eventType = parser.getEventType();
                if (eventType == XmlPullParser.TEXT)
                    cssStyle.Version = parser.getText();
            } else if (name.equals("author")) {
                parser.next();
                eventType = parser.getEventType();
                if (eventType == XmlPullParser.TEXT)
                    cssStyle.Author = parser.getText();
            } else if (name.equals("comment")) {
                parser.next();
                eventType = parser.getEventType();
                if (eventType == XmlPullParser.TEXT)
                    cssStyle.Comment = parser.getText();
            } else if (name.equals("screenshot")) {
                cssStyle.ScreenShots.add(parseScreenShot(parser));
            }

        }
    }
    return cssStyle;
}
 
Example 15
Source File: AtomTest.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
/**
 * Read an XML ATOM Feed from a file to a string and assert if all the {@link FeedEntry}s are
 * present. No detailed assertion of each element
 *
 * <p>The purpose of this test is to read a bunch of elements which contain additional elements
 * (HTML in this case), that are not part of the {@link FeedEntry} and to see if there is an issue
 * if we parse some more entries.
 */
@Test
public void testSampleFeedParser() throws Exception {
  XmlPullParser parser = Xml.createParser();
  URL url = Resources.getResource("sample-atom.xml");
  String read = Resources.toString(url, Charsets.UTF_8);
  parser.setInput(new StringReader(read));
  XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
  AbstractAtomFeedParser atomParser =
      new AtomFeedParser<Feed, FeedEntry>(
          namespaceDictionary,
          parser,
          new ByteArrayInputStream(read.getBytes()),
          Feed.class,
          FeedEntry.class);
  Feed feed = (Feed) atomParser.parseFeed();
  assertNotNull(feed);

  // validate feed 1 -- Long Content
  FeedEntry entry = (FeedEntry) atomParser.parseNextEntry();
  assertNotNull(entry);
  assertNotNull(entry.id);
  assertNotNull(entry.title);
  assertNotNull(entry.summary);
  assertNotNull(entry.link);
  assertNotNull(entry.updated);
  assertNotNull(entry.content);
  assertEquals(5000, entry.content.length());

  // validate feed 2 -- Special Charts
  entry = (FeedEntry) atomParser.parseNextEntry();
  assertNotNull(entry);
  assertNotNull(entry.id);
  assertNotNull(entry.title);
  assertNotNull(entry.summary);
  assertNotNull(entry.link);
  assertNotNull(entry.updated);
  assertNotNull(entry.content);
  assertEquals(
      "aäb cde fgh ijk lmn oöpoöp tuü vwx yz AÄBC DEF GHI JKL MNO ÖPQ RST UÜV WXYZ "
          + "!\"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¼× {} aäb cde fgh ijk lmn oöp qrsß tuü vwx yz "
          + "AÄBC DEF GHI JKL MNO",
      entry.content);

  // validate feed 3 -- Missing Content
  entry = (FeedEntry) atomParser.parseNextEntry();
  assertNotNull(entry);
  assertNotNull(entry.id);
  assertNotNull(entry.title);
  assertNotNull(entry.summary);
  assertNotNull(entry.link);
  assertNotNull(entry.updated);
  assertNull(entry.content);

  // validate feed 4 -- Missing Updated
  entry = (FeedEntry) atomParser.parseNextEntry();
  assertNotNull(entry);
  assertNotNull(entry.id);
  assertNotNull(entry.title);
  assertNotNull(entry.summary);
  assertNotNull(entry.link);
  assertNull(entry.updated);
  assertNotNull(entry.content);

  // validate feed 5
  entry = (FeedEntry) atomParser.parseNextEntry();
  assertNotNull(entry);
  assertNotNull(entry.id);
  assertNotNull(entry.title);
  assertNull(entry.summary);
  assertNotNull(entry.link);
  assertNotNull(entry.updated);
  assertNotNull(entry.content);

  // validate feed 6
  entry = (FeedEntry) atomParser.parseNextEntry();
  assertNull(entry);

  atomParser.close();
}
 
Example 16
Source File: ParserXml.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
/**
 * ���������н���Xml�ļ�
 * @param is
 * 			������
 * @return
 * 			null:��ʾ����Xml�ļ�����
 */
public static List<NewsBean> parserXmlFromStream(InputStream is){
	List<NewsBean> newsList = new ArrayList<NewsBean>();
	try {
		// 1. ��ʼ��Xml������
		XmlPullParser parser = Xml.newPullParser();
		// 2. ����������
		parser.setInput(is, "utf-8");
		// 3. ��������
		int type = parser.getEventType();
		NewsBean bean = null;
		
		while(type != XmlPullParser.END_DOCUMENT){
			//��ʼ���߽�����ǩ
			String tag = parser.getName();
			switch (type) {
			case XmlPullParser.START_TAG://��ʼ��ǩ
				if("item".equals(tag)){			//ÿ��������Ŀ�Ŀ�ʼ��ǩ
					bean  = new NewsBean();
				}else if("title".equals(tag)){	//���ŵı���
					String title = parser.nextText();
					bean.setTitle(title);
				}else if("des".equals(tag)){	//���ŵ�����
					String des = parser.nextText();
					bean.setDes(des);
				}else if("image".equals(tag)){	//���ŵ�ͼƬ��Url
					String imageUrl = parser.nextText();
					bean.setImage(imageUrl);
				}else if("comment".equals(tag)){//���ŵ�����
					String comment = parser.nextText();
					bean.setComment(comment);
				}
				break;
			case XmlPullParser.END_TAG://������ǩ
				if("item".equals(tag)){			//ÿ��������Ŀ�Ľ�����ǩ
					newsList.add(bean);
				}
				break;

			default:
				break;
			}
			
			//�õ���һ���¼�
			type = parser.next();
		}
		
		return newsList;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
Example 17
Source File: XmlUtils.java    From HtmlCompat with Apache License 2.0 3 votes vote down vote up
/**
 * 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.
 *
 * @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]);
}
 
Example 18
Source File: XmlUtils.java    From a with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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.
 * @throws XmlPullParserException
 * @throws java.io.IOException
 * @see #readValueXml
 * @see #readThisSetXml
 * @see #writeSetXml
 */
public static HashSet readSetXml(InputStream in)
        throws XmlPullParserException, java.io.IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(in, null);
    return (HashSet) readValueXml(parser, new String[1]);
}
 
Example 19
Source File: XmlUtils.java    From MyBookshelf with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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
 * @see #readValueXml
 * @see #readThisListXml
 * @see #writeListXml
 */
public static ArrayList readListXml(InputStream in)
        throws XmlPullParserException, java.io.IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(in, null);
    return (ArrayList) readValueXml(parser, new String[1]);
}
 
Example 20
Source File: XmlUtils.java    From MyBookshelf with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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.
 * @throws XmlPullParserException
 * @throws java.io.IOException
 * @see #readValueXml
 * @see #readThisSetXml
 * @see #writeSetXml
 */
public static HashSet readSetXml(InputStream in)
        throws XmlPullParserException, java.io.IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(in, null);
    return (HashSet) readValueXml(parser, new String[1]);
}