码迷,mamicode.com
首页 > 其他好文 > 详细

Tomcat - 网络XML DOM/SAX/PULL解析

时间:2014-11-26 18:19:38      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:des   android   cWeb   style   blog   http   io   ar   color   

首先, 解析本地的XML 参考     http://www.cnblogs.com/iMirror/p/4122082.html

学习Tomcat搭建本地服务器 参考

 

  在Tomcat默认访问目录 webapps/ROOT下新建XMLParserTest文件夹, 并新建persons.xml

    bubuko.com,布布扣

  peosons..xml

    bubuko.com,布布扣

  打开Tomcat , 查询IP地址, 打开该 persons.xml 可以通过访问 “http://192.168.1.111:8080/XMLParserTest/persons.xml”

  浏览器打开之后的截图

    bubuko.com,布布扣

  Genymotion打开截图

    bubuko.com,布布扣

  这就是说明访问该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解析

标签:des   android   cWeb   style   blog   http   io   ar   color   

原文地址:http://www.cnblogs.com/iMirror/p/4123675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!