利用百度全网寻人这个平台的接口,练习一下如何解析收到的xml数据包
使用开源的dom4j对收到的xml数据包进行遍历
说句题外话,在解析过程中发现结果中的寻人信息中有些脑残在利用这个平台发布虚假的寻人启事进行娱乐,对于这种人真的不知道说什么好...
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import org.dom4j.*;
public class DomDemo
{
public static LinkedList<String> name=new LinkedList<String>();
public static LinkedList<String> sex =new LinkedList<String>();
public static LinkedList<String> desc=new LinkedList<String>();
public static LinkedList<String> remarks=new LinkedList<String>();
public static LinkedList<String> phone=new LinkedList<String>();
public static void getElementList(Element e)
{
List elements=e.elements();
Info info=new Info();
if(elements.size()==0)
{
if(e.getName().equals("name"))
{
name.add(e.getTextTrim());
}
else if(e.getName().equals("sex"))
{
sex.add(e.getTextTrim());
}
else if(e.getName().equals("desc"))
{
desc.add(e.getTextTrim());
}
else if(e.getName().equals("phone"))
{
phone.add(e.getTextTrim());
}
else if(e.getName().equals("remarks"))
{
remarks.add(e.getTextTrim());
}
//System.out.println(e.getTextTrim());
}
else
{
Iterator it=elements.iterator();
while(it.hasNext())
{
Element eL=(Element)