Android Open Source - 1040_searchlit Names Parser






From Project

Back to project page 1040_searchlit.

License

The source code is released under:

GNU General Public License

If you think the Android project 1040_searchlit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.build2;
//  w  w  w .  j  av a 2  s . c o  m
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class NamesParser {
  
  Item objItem;
  List<Item> listArray;

  //public List<Item> getData(String url) {
  public List<Item> getData(InputStream in) {
    try {

      listArray = new ArrayList<Item>();//
      
      
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(in);
      
      //Document doc = db.parse(responce.getEntity().getContent());
      
      
      //URL.openStream returns input stream reader

      doc.getDocumentElement().normalize();

      NodeList nList = doc.getElementsByTagName("item");

      for (int temp = 0; temp < nList.getLength(); temp++) {

        Node nNode = nList.item(temp);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {

          Element eElement = (Element) nNode;

          objItem = new Item();

          objItem.setId(getTagValue("id", eElement));
          objItem.setTitle(getTagValue("title", eElement));
          objItem.setDesc(getTagValue("desc", eElement));
          objItem.setPubdate(getTagValue("pubDate", eElement));
          objItem.setLink(getTagValue("link", eElement));
          objItem.setLink1(getTagValue("link1", eElement));
          objItem.setIsbn(getTagValue("isbn", eElement));
          
          
          
          listArray.add(objItem);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return listArray;
  }

  private static String getTagValue(String sTag, Element eElement) {
    NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
        .getChildNodes();

    Node nValue = (Node) nlList.item(0);

    return nValue.getNodeValue();

  }
}




Java Source Code List

com.example.build2.Content.java
com.example.build2.DetailActivity.java
com.example.build2.Item.java
com.example.build2.Last.java
com.example.build2.MainActivity.java
com.example.build2.NamesParser.java
com.example.build2.NewsRowAdapter.java
com.example.build2.Utils.java
com.example.build2.myMenu.java
com.example.build2.work.java