android---pull解析<db:attribute name="isbn10">7111337271</db:attribute>

 
 
 
-------------------------------------------------------------------------------domain
 
package com.sforus.TextShangJi.domain;

public class Book {
	private String title;
	private String author;
	private String isbn13;
	private String publisher;
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getIsbn13() {
		return isbn13;
	}
	public void setIsbn13(String isbn13) {
		this.isbn13 = isbn13;
	}
	public String getPublisher() {
		return publisher;
	}
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	
	
}


 
 
 
 
 
---------------------------------------------------------------
下面是处理xml
 
--------------------------------------------------------------
package com.sforus.TextShangJi.util;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import com.sforus.TextShangJi.domain.Book;

import android.content.Context;
import android.util.Xml;

import com.google.gdata.client.douban.DoubanService;

import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Source;

/**
 * 访问数据库,获取书本
 * 
 * @author woops
 * 
 */
public class ConnectDataBase {

	private Book book;

	public List<Book> getNewBooks() throws Exception {
		
		 List<Book> books = null;   

		String path = "http://api.douban.com/book/subjects?tag=android&start-index=1&max-results=5";
		URL url = new URL(path);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setConnectTimeout(5000);
		InputStream inStream = conn.getInputStream();

		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(inStream, "UTF-8");

		int eventType = parser.getEventType();// 产生第一个事件
		while (eventType != XmlPullParser.END_DOCUMENT) {
			boolean s=false;
			switch (eventType) {
			case XmlPullParser.START_DOCUMENT:
				books = new ArrayList<Book>();
				break;
			

case XmlPullParser.START_TAG:     if ("entry".equals(parser.getName())) {       book = new Book();            }     if (book!=null) {      if ("title".equals(parser.getName())) {       String title=parser.nextText().toString();       book.setTitle(title);      }      if ("name".equals(parser.getName())){

      String name=parser.nextText().toString();       book.setAuthor(name);      }      if ("name".equals(parser.getName()==null)) {       String name=null;       book.setAuthor(name);      }      if("attribute".equals(parser.getName())){            if ("isbn13".equals(parser.getAttributeValue(0))) {         book.setIsbn13( parser.nextText());             }else if ("publisher".equals(parser.getAttributeValue(0))) {              book.setPublisher( parser.nextText());       }      }     }     break;    case XmlPullParser.END_TAG:     if ("entry".equals(parser.getName())&& eventType == XmlPullParser.END_TAG ) {      books.add(book);      book=null;     }     break;    }    eventType=parser.next();   }   return books;

} }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
用python帮我把下面标签中的有效数据提取出来<annotation> <folder>converted/CMS/2D目标检测/filter</folder> <filename>converted/CMS/2D目标检测/filter_empty_target_img_after_hash2/0/20230401180910649_61.jpg</filename> <source> <database>Unknown</database> <annotation>Unknown</annotation> <image>Unknown</image> </source> <size> <width>1920</width> <height>1536</height> <depth></depth> </size> <segmented>0</segmented> <object> <name>二轮车</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>626.38</xmin> <ymin>808.12</ymin> <xmax>650.03</xmax> <ymax>852.04</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>6</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> <object> <name>行人</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>1612.74</xmin> <ymin>831.51</ymin> <xmax>1627.34</xmax> <ymax>873.8</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>8</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> <object> <name>行人</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>1469.0</xmin> <ymin>832.96</ymin> <xmax>1489.43</xmax> <ymax>865.8</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>9</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> </annotation>
07-20

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值