首页 > 代码库 > Tomcat - 网络XML DOM/SAX/PULL解析
Tomcat - 网络XML DOM/SAX/PULL解析
首先, 解析本地的XML 参考 http://www.cnblogs.com/iMirror/p/4122082.html
学习Tomcat搭建本地服务器 参考
在Tomcat默认访问目录 webapps/ROOT下新建XMLParserTest文件夹, 并新建persons.xml
peosons..xml
打开Tomcat , 查询IP地址, 打开该 persons.xml 可以通过访问 “http://192.168.1.111:8080/XMLParserTest/persons.xml”
浏览器打开之后的截图
Genymotion打开截图
这就是说明访问该URL可以得到返回XML
修改本地访问XML程序中的XMLParseActivity.java如下
package mirror.android.XMLParseActivity;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import org.apache.http.HttpConnection;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import mirror.android.Services.DOMParseService;import mirror.android.Services.PULLParseService;import mirror.android.Services.SAXParseService;import mirror.android.resolvexml.R;import android.app.Activity;import android.os.Bundle;public class XMLParseActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_xmlparse); new Thread(new Runnable() { @Override public void run() { try { String urlString = "http://192.168.1.111:8080/XMLParserTest/persons.xml"; URL url = new URL(urlString); HttpURLConnection con = (HttpURLConnection)url.openConnection(); if(con.getResponseCode() == 200){ InputStream in = con.getInputStream();
DOMParseService domParseService = new DOMParseService();
domParseService.getPersonsByParseXML(in); SAXParseService saxParseService = new SAXParseService(); saxParseService.getPersonsByParseXML(in2); PULLParseService pullParseService = new PULLParseService(); pullParseService.getPersonsByParseXML(in3);
SAXParseService saxParseService = new SAXParseService(); saxParseService.getPersonsByParseXML(in); } } catch (Exception e) { e.getStackTrace(); } } }).start(); /*try { InputStream in1 = getAssets().open("persons.xml"); InputStream in2 = getAssets().open("persons.xml"); InputStream in3 = getAssets().open("persons.xml"); DOMParseService domParseService = new DOMParseService(); domParseService.getPersonsByParseXML(in1); SAXParseService saxParseService = new SAXParseService(); saxParseService.getPersonsByParseXML(in2); PULLParseService pullParseService = new PULLParseService(); pullParseService.getPersonsByParseXML(in3); } catch (IOException e) { e.printStackTrace(); }*/ }}
Tomcat - 网络XML DOM/SAX/PULL解析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。