import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.wasu.kaku.entity.Coupon;
public class TestMain {
/**
* @param args
* @throws DocumentException
* @throws IOException
*/
public static void main(String[] args) throws DocumentException, IOException {
// TODO Auto-generated method stub
String urlStr = "http://zkpartner3.mooo.com/wfjdeliver/pub/v1/coupon/filter/?cal=pat3&sk=oiu32m34&outp=full&loc=016";
URL url = new URL(urlStr);
List<Coupon> CouponArrayList=new ArrayList<Coupon>();
Document document = null;
SAXReader saxReader = new SAXReader();
// String strTest="<name>11</name>";
document = saxReader.read(url);
List Couponlist = document.selectNodes("//ApiResult/CouponList/Coupons/Coupon " );
Iterator Coupons=Couponlist.iterator();
System.out.println("店面个数为"+Couponlist.size());
while(Coupons.hasNext()){
Coupon sc = new Coupon();
Element Coupon=(Element)Coupons.next();
//name
Element name=Coupon.element("Title");
sc.setName(name.getText());
//ID
System.out.print(((Attribute )Coupon.attribute("id")).getValue());
sc.setCid(((Attribute )Coupon.attribute("id")).getValue());
System.out.println(sc.getCid());
//Advertiser
//Description
Element description=Coupon.element("Description");
sc.setDesc(description.getText());
System.out.print(description.getText());
//ImageUrl
Element imageUrl=Coupon.element("ImageUrl");
sc.setImg(imageUrl.getText());
//StartDate
Element startDate=Coupon.element("StartDate");
sc.setImg(startDate.getText());
//EndDate
Element endDate=Coupon.element("EndDate");
sc.setImg(endDate.getText());
//shop
Element advertiser=Coupon.element("Advertiser");
System.out.print(((Attribute )advertiser.attribute("name")).getValue());
sc.setShop(((Attribute )advertiser.attribute("name")).getValue());
CouponArrayList.add(sc);
}
}
}
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.wasu.kaku.entity.Coupon;
public class TestMain {
/**
* @param args
* @throws DocumentException
* @throws IOException
*/
public static void main(String[] args) throws DocumentException, IOException {
// TODO Auto-generated method stub
String urlStr = "http://zkpartner3.mooo.com/wfjdeliver/pub/v1/coupon/filter/?cal=pat3&sk=oiu32m34&outp=full&loc=016";
URL url = new URL(urlStr);
List<Coupon> CouponArrayList=new ArrayList<Coupon>();
Document document = null;
SAXReader saxReader = new SAXReader();
// String strTest="<name>11</name>";
document = saxReader.read(url);
List Couponlist = document.selectNodes("//ApiResult/CouponList/Coupons/Coupon " );
Iterator Coupons=Couponlist.iterator();
System.out.println("店面个数为"+Couponlist.size());
while(Coupons.hasNext()){
Coupon sc = new Coupon();
Element Coupon=(Element)Coupons.next();
//name
Element name=Coupon.element("Title");
sc.setName(name.getText());
//ID
System.out.print(((Attribute )Coupon.attribute("id")).getValue());
sc.setCid(((Attribute )Coupon.attribute("id")).getValue());
System.out.println(sc.getCid());
//Advertiser
//Description
Element description=Coupon.element("Description");
sc.setDesc(description.getText());
System.out.print(description.getText());
//ImageUrl
Element imageUrl=Coupon.element("ImageUrl");
sc.setImg(imageUrl.getText());
//StartDate
Element startDate=Coupon.element("StartDate");
sc.setImg(startDate.getText());
//EndDate
Element endDate=Coupon.element("EndDate");
sc.setImg(endDate.getText());
//shop
Element advertiser=Coupon.element("Advertiser");
System.out.print(((Attribute )advertiser.attribute("name")).getValue());
sc.setShop(((Attribute )advertiser.attribute("name")).getValue());
CouponArrayList.add(sc);
}
}
}