DOM解析器在Android 4.0的API [英] Dom parser in android 4.0 API

查看:123
本文介绍了DOM解析器在Android 4.0的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是DOM解析器不工作在Android 4.0的,但它工作在2.2,如果我运行该项目在我的4.0模拟器比低于行不执行,这是不给任何错误。

My Problem is Dom Parser is not working in Android 4.0 but it's working on 2.2, if i run the project in my 4.0 emulator than below line not execute and this is not give any error.

Document doc = db.parse(inStream);

以下是我的Java code: -

Following is my Java Code:-

public class TestParsingActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        StringBuffer sb = new StringBuffer();

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);

        System.setProperty("http.proxySet", "true");
        System.setProperty("http.proxyHost", "192.168.1.220");
        System.setProperty("http.proxyPort", "315");

        String NAMESPACE = "Dipak";
        String SOAP_ACTION = "Dipak/Start";
        String METHOD_NAME = "Start";
        String url = "http://google.co.uk/Dip/service1.asmx";

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo p = new PropertyInfo();
        String qry = "select Password from Profiles where ID = (select uid from userprofiles where name = 'Dipak')";

        p.setName("SQL");
        p.setValue(qry);
        request.addProperty(p);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE httpTransport = new HttpTransportSE(url);
        httpTransport.debug = true;

        System.out.println("three**************");

        try {
            httpTransport.call(SOAP_ACTION, envelope);
            System.out.println("four**************");
            // SoapObject response=(SoapObject)envelope.bodyIn;
            SoapObject response = (SoapObject) envelope.getResponse();

            System.out.println("response =====>>>> "
                    + response.getProperty(0).toString());
            // SoapObject response=(SoapObject)envelope.getResponse();
            // SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            System.out.println("success**************");

            sb.append(response);
            System.out.println("Data from Search Job =====>>>> "
                    + sb.toString());
            // return response.toString();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory
                    .newInstance();

            DocumentBuilder db = factory.newDocumentBuilder();
            InputSource inStream = new InputSource();

            System.out.println("Data from try  =====>>>> " + sb.toString());

            inStream.setCharacterStream(new StringReader(sb.toString()));

            System.out
                    .println("Data from try  =====>>>>11111111111111111111111111111 ");

            Document doc = db.parse(inStream);
            System.out
                    .println("Data from try  =====>>>>22222222222222222222222222222 ");

            Element root = doc.getDocumentElement();

            String root1 = doc.getTextContent();
            System.out
                    .println("Value of root................................................................................"
                            + root);
            System.out
                    .println("Value of root1................................................................................"
                            + root1);
            System.out
                    .println("................................................................................5");
        } catch (Exception e) {
            // TODO: handle exception
        }

    }
}

任何帮助,将AP preciated,对不起我的英语不好沟通。

Any Help Would be appreciated, sorry for my bad English communication.

推荐答案

你为什么不使用

response.getPropertyAsString(index);

response.getPropertyAsString("PROPERTY_NAME");

但是,你仍然想使用DOM解析器,你可以使用 HttpTransportSE.responseDump 来获得响应XML格式,并尝试解析XML,而不是ksaop2的响应格式。

But you still would like to use Dom parser, you can use HttpTransportSE.responseDump to get response in XML format and try parsing XML instead of ksaop2's response format.

这篇关于DOM解析器在Android 4.0的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆