English 中文(简体)
4.0 API内和4.0机器人内多姆采集器
原标题:Dom parser in android 4.0 API

我的问题是Dom Parser没有在 Android 4. 0 中工作,但是它在2.2中工作, 如果我用我的4.0模拟器运行项目, 而不是在线下不执行, 这不会造成任何错误 。

Document doc = db.parse(inStream);

以下是我的爪哇代码:

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
        }

    }
}

任何帮助都是感激不尽的 抱歉我英语交流不畅

最佳回答

你何不用

response.getPropertyAsString(index);

response.getPropertyAsString("PROPERTY_NAME");

?????

But you still would like to use Dom parser, you can use HttpTransp或tSE.responseDump to get response in XML f或mat and try parsing XML instead of ksaop2 s response f或mat.

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签