81,094
社区成员
发帖
与我相关
我的任务
分享
String content = "<xml....";
ByteArrayInputStream is = new ByteArrayInputStream(content.getBytes());
SAXReader reader = new SAXReader();
Document document = null;
try {
document = reader.read(is);
} catch (DocumentException e) {
e.printStackTrace();
} finally {
is.close();
}
if(document == null){
return null;
}
Element root = document.getRootElement();
import java.io.*;
import java.net.*;
/**
* Created by Administrator on 14-11-11.
*/
public class Test1 {
public static void main(String args[]) throws IOException {
//URL url = new URL("http://bbs.csdn.net/forums/Java.atom");
String url = "http://bbs.csdn.net/forums/Java.atom";
System.out.println(readXMlContent(url));
}
public static String readXMlContent(String url) throws IOException {
StringBuffer temp = new StringBuffer();
URLConnection uc = new URL(url).openConnection();
uc.setConnectTimeout(10000);
uc.setDoOutput(true);
InputStream in = new BufferedInputStream(uc.getInputStream());
Reader rd = new InputStreamReader(in,"UTF-8");
int c = 0;
while ((c = rd.read()) != -1) {
temp.append((char) c);
}
in.close();
return temp.toString();
}
}