期望嵌套的XML结构但接收SOAP结构

时间:2021-07-15 13:23:26

I'm making an app that is requesting data from a Web Service (implementing Soap).

我正在创建一个从Web服务请求数据的应用程序(实现Soap)。

People who are viewing this pleaase post doubts in comments... I havent got any response to the question do ask me if there is any doubts, i really need help, am stuck!!

正在观看这个请求的人在评论中表示怀疑......我没有得到任何回答问题请问我是否有任何疑问,我真的需要帮助,我被困!

So to make request I have to use ksoap libraries.. the Web service is coded to return a response of type XML. When the web service itself is tested on a browser it displays a result which is as follows:

因此,为了发出请求,我必须使用kso​​ap库.Web服务被编码为返回XML类型的响应。在浏览器上测试Web服务本身时,它会显示如下结果:

?xml version="1.0" encoding="utf-8" ?> 
- <SOBKeyList>
- <Key>
  <value>12686</value> 
  </Key>
- <Key>
  <value>16238</value> 
  </Key>
- <Key>
  <value>26978</value> 
  </Key>
  </SOBKeyList>

clearly an XML file...

显然是一个XML文件......

However when i use ths code to get a result:

但是,当我使用该代码获得结果时:

    public String getXmlFromUrl(String url) {
    // TODO Auto-generated method stub
    String xml = null;
    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
    PropertyInfo pi = new PropertyInfo();

    pi.setName("fkey");
    pi.setValue(0);
    pi.setType(Integer.class);
    request.addProperty(pi);

    pi = new PropertyInfo();

    pi.setName("tkey");
    pi.setValue(999999);
    pi.setType(Integer.class);
    request.addProperty(pi);


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE httpTransport = new HttpTransportSE(url);
    Object response = null; 

    try {
        httpTransport.call(SOAP_ACTION, envelope);
        response = envelope.getResponse();
        xml = response.toString();
        Log.d("xml:", xml);
    } catch (SoapFault e) {
        // TODO Auto-generated catch block
        Log.d("Soap Fault", e.toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d("IOexception", e.toString());
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        Log.d("XmlPullParserException", e.toString());
    }

    return xml;
}

It returns a nested SOAP structure confirmed by the Log entry which i make ( Log.d("xml:", xml); ) The corresponding LogCat entry is: (i've formatted it to make it the SOAP structure's heirarchy apparent... )

它返回一个由我生成的Log条目确认的嵌套SOAP结构(Log.d(“xml:”,xml);)相应的LogCat条目是:(我已将其格式化为使其成为SOAP结构的层次结构明显... 。)

anyType{
      SOBKeyList=anyType{
                          Key=anyType{value=12686 ; };
                          Key=anyType{value=16238 ; };
                          Key=anyType{value=26978 ; };
                         };
          }

The reason why i necessarily need an XML is because later I parse the string to get a DOM element and when the above string is passed it returns the following:

我之所以需要XML的原因是因为后来我解析字符串以获取DOM元素,并且当传递上述字符串时,它返回以下内容:

org.xml.sax.SAXParseException: Unexpected token (position:TEXT anyType{SOBKeyLi...@1:119 in java.io.StringReader@40ec9c68)

org.xml.sax.SAXParseException:意外的标记(位置:TEXT anyType {SOBKeyLi ... java.io.StringReader@40ec9c68中的@ 1:119)

also from there onward my entire code depends on the fact that the response was XML.

从那时起我的整个代码依赖于响应是XML的事实。

Explaination of the reason why i expected an XML : Now you may asked why I coded my app expecting XML when i had not tested the Web service the reason is: The Web service was coded my a third party who assured me of an XML response , now i dont have enough time to change my remaining code to exploit a SOAP structure !! -_- I'm in a fix. Please help!

解释为什么我期望XML的原因:现在你可能会问我为什么在没有测试Web服务的情况下编写我的应用程序期望XML的原因是:Web服务编码我的第三方谁向我保证XML响应,现在我没有足够的时间来改变我的剩余代码来利用SOAP结构! -_-我正在解决问题。请帮忙!

1 个解决方案

#1


1  

Try this:

尝试这个:

String responseXML = httpTransport.responseDump;
  • HttpTransportSE.responseDump gives you response in XML format.
  • HttpTransportSE.responseDump以XML格式为您提供响应。
  • HttpTransportSE.requestDump gives you request in XML format.
  • HttpTransportSE.requestDump以XML格式提供请求。

However to be able to change and retrieve any of these values you must set the debug field of HttpTransportSE to true so your code should look like...

但是,为了能够更改和检索这些值中的任何一个,您必须将HttpTransportSE的调试字段设置为true,以便您的代码看起来像......

    HttpTransportSE httpTransport = new HttpTransportSE(url);
    httpTransport.debug =true;      
    try {
        httpTransport.call(SOAP_ACTION, envelope);          
        xml = httpTransport.responseDump;
        Log.d("xml:", "is:" + xml);     
    }

Also you can parse your response like as follow:

您也可以解析您的回复,如下所示:

ArrayList<String> listValues = new ArrayList<String>();

            httpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject) envelope.getResponse();

            SoapObject soapSOBKeyList = (SoapObject) response.getProperty("SOBKeyList");

            int keyCount = soapSOBKeyList.getPropertyCount();

            for (int i = 0; i < keyCount; i++) {
                String value = soapSOBKeyList.getPropertyAsString(i);
                listValues.add(value);
            }

            return listValues;

#1


1  

Try this:

尝试这个:

String responseXML = httpTransport.responseDump;
  • HttpTransportSE.responseDump gives you response in XML format.
  • HttpTransportSE.responseDump以XML格式为您提供响应。
  • HttpTransportSE.requestDump gives you request in XML format.
  • HttpTransportSE.requestDump以XML格式提供请求。

However to be able to change and retrieve any of these values you must set the debug field of HttpTransportSE to true so your code should look like...

但是,为了能够更改和检索这些值中的任何一个,您必须将HttpTransportSE的调试字段设置为true,以便您的代码看起来像......

    HttpTransportSE httpTransport = new HttpTransportSE(url);
    httpTransport.debug =true;      
    try {
        httpTransport.call(SOAP_ACTION, envelope);          
        xml = httpTransport.responseDump;
        Log.d("xml:", "is:" + xml);     
    }

Also you can parse your response like as follow:

您也可以解析您的回复,如下所示:

ArrayList<String> listValues = new ArrayList<String>();

            httpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject) envelope.getResponse();

            SoapObject soapSOBKeyList = (SoapObject) response.getProperty("SOBKeyList");

            int keyCount = soapSOBKeyList.getPropertyCount();

            for (int i = 0; i < keyCount; i++) {
                String value = soapSOBKeyList.getPropertyAsString(i);
                listValues.add(value);
            }

            return listValues;