期待嵌套的XML结构,但接收SOAP结构 [英] Expecting Nested XML structure but receiving SOAP structure
问题描述
我正在做一个从(实施SOAP)Web服务请求数据的应用程序。
I'm making an app that is requesting data from a Web Service (implementing Soap).
谁在评论查看此pleaase后怀疑人... ...我还没有得到这个问题的任何响应都问我,如果有任何疑问,我真的很需要帮助,我坚持!
因此,为了使要求我必须使用KSOAP库.. Web服务为 codeD返回XML类型的响应。当web服务本身上的浏览器进行测试它显示的结果是,如下所示:
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:
?xml version="1.0" encoding="utf-8" ?>
- <SOBKeyList>
- <Key>
<value>12686</value>
</Key>
- <Key>
<value>16238</value>
</Key>
- <Key>
<value>26978</value>
</Key>
</SOBKeyList>
显然是一个 XML 文件...
然而
当我使用的部份code得到的结果:
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;
}
它返回一个嵌套SOAP结构 确认的由日志条目,我做( Log.d(XML,XML);
)
相应的LogCat中条目:(我已经格式化它,使之成为SOAP结构的层次结构明显...)
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... )
anyType{
SOBKeyList=anyType{
Key=anyType{value=12686 ; };
Key=anyType{value=16238 ; };
Key=anyType{value=26978 ; };
};
}
我为什么一定需要一个XML的原因是因为我稍后解析字符串得到的 DOM 元素,当上面的字符串传递返回如下:
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:
org.xml.sax.SAXParseException:意外的令牌(位置:TEXT anyType的{SOBKeyLi ... @ 1:119 java.io.StringReader@40ec9c68)
org.xml.sax.SAXParseException: Unexpected token (position:TEXT anyType{SOBKeyLi...@1:119 in java.io.StringReader@40ec9c68)
还从那儿以后我的整个$ C $,c取决于一个事实,即反应的 XML 。
also from there onward my entire code depends on the fact that the response was XML.
为什么我预期的XML 的原因阐释:
现在你可能会问我为什么codeD我的应用程序期待XML时,我没有测试Web服务的原因是:Web服务是codeD我的第三方谁向我保证一个XML响应,目前我没有足够的时间来改变我剩下的code利用一个SOAP结构!
-_-
我在一个修补程序。请帮助!
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!
推荐答案
试试这个:
String responseXML = httpTransport.responseDump;
-
HttpTransportSE.responseDump
为您提供了XML格式的响应。 -
HttpTransportSE.requestDump
为您提供了XML格式的要求。 HttpTransportSE.responseDump
gives you response in XML format.HttpTransportSE.requestDump
gives you request in XML format.
然而,为了能够改变和检索这些值必须设置 HttpTransportSE
的调试
字段的真正
所以你的code应该像...
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 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;
这篇关于期待嵌套的XML结构,但接收SOAP结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!