我想在android中调用this WSDL file来检索数据。
这是RPC / Literal WSDL结构,但我无法解析它。我已经解析了基于SOAP的普通WSDL文件。
请帮我解决这个问题。
代码:
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class WebServiceRecetrioActivity extends Activity
{
Button btnReg;
EditText fullName,emailId,password,confirmPwd;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.registration_main);
btnReg = (Button)findViewById(R.id.regId);
fullName = (EditText)findViewById(R.id.name);
emailId = (EditText)findViewById(R.id.emailId);
password = (EditText)findViewById(R.id.pwd);
confirmPwd = (EditText)findViewById(R.id.pwd1);
btnReg.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String xmlString = "http://www.danica.com.ar/recetario/recetario.wsdl"; //Added your wsdl as an xml string here
try {
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser pullParser = parserFactory.newPullParser();
pullParser.setInput(new StringReader(xmlString));
int eventType = pullParser.getEventType();
while (true)
{
if(eventType == XmlPullParser.START_TAG)
{
String Tag = pullParser.getName();
System.out.println(Tag);
}
else if(eventType == XmlPullParser.END_DOCUMENT)
break;
eventType = pullParser.next();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
例外:
03-07 16:39:52.297: W/System.err(767): org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT http://www.danic...@1:50 in java.io.StringReader@41223d10)
03-07 16:39:52.297: W/System.err(767): at org.kxml2.io.KXmlParser.next(KXmlParser.java:426)
03-07 16:39:52.297: W/System.err(767): at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
03-07 16:39:52.297: W/System.err(767): at com.webservice.WebServiceRecetrioActivity$1.onClick(WebServiceRecetrioActivity.java:62)
03-07 16:39:52.297: W/System.err(767): at android.view.View.performClick(View.java:4084)
03-07 16:39:52.297: W/System.err(767): at android.view.View$PerformClick.run(View.java:16966)
03-07 16:39:52.297: W/System.err(767): at android.os.Handler.handleCallback(Handler.java:615)
03-07 16:39:52.297: W/System.err(767): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 16:39:52.307: W/System.err(767): at android.os.Looper.loop(Looper.java:137)
03-07 16:39:52.307: W/System.err(767): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-07 16:39:52.317: W/System.err(767): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 16:39:52.317: W/System.err(767): at java.lang.reflect.Method.invoke(Method.java:511)
03-07 16:39:52.327: W/System.err(767): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-07 16:39:52.327: W/System.err(767): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-07 16:39:52.327: W/System.err(767): at dalvik.system.NativeStart.main(Native Method)
我使用了ksoap2-android-assembly-3.1.1-jar-with-dependencies.jar
答案 0 :(得分:1)
使用ksoapxml库。它有你可以使用的xml pull解析器。
String xmlString = ""; //Added your wsdl as an xml string here
try {
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser pullParser = parserFactory.newPullParser();
pullParser.setInput(new StringReader(xmlString));
int eventType = pullParser.getEventType();
while (true)
{
if(eventType == XmlPullParser.START_TAG)
{
String Tag = pullParser.getName();
System.out.println(Tag);
}
else if(eventType == XmlPullParser.END_DOCUMENT)
break;
eventType = pullParser.next();
}
输出如下:
definitions
types
schema
complexType
all
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
complexType
all
element
element
element
element
element
complexType
sequence
element
complexType
sequence
element
complexType
all
element
element
element
element
element
element
complexType
sequence
element
complexType
all
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
element
complexType
sequence
element
complexType
all
element
element
element
element
element
element
message
part
message
part
message
part
part
message
part
message
part
part
message
part
part
part
message
part
message
part
message
part
message
part
message
part
message
part
message
part
part
message
part
portType
operation
input
output
operation
input
output
operation
input
output
operation
input
output
operation
input
output
operation
input
output
operation
input
output
binding
soap:binding
operation
soap:operation
input
soap:body
output
soap:body
operation
soap:operation
input
soap:body
output
soap:body
operation
soap:operation
input
soap:body
output
soap:body
operation
soap:operation
input
soap:body
output
soap:body
operation
soap:operation
input
soap:body
output
soap:body
operation
soap:operation
input
soap:body
output
soap:body
operation
soap:operation
input
soap:body
output
soap:body
service
documentation
port
soap:address
HttpClient httpCLient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(serverUrl);
HttpResponse httpresponse = httpClient.execute(httpGet);
HttpEntity resEntity = httpresponse.getEntity();
String result = EntityUtils.toString(resEntity);
将结果传递给解析器。
获取每个标记的所有属性和值的列表
int count = pullParser.getAttributeCount();
for(int i=0;i<count;i++)
{
Log.d("App", pullParser.getAttributeName(i) + ":" + pullParser.getAttributeValue(i));
}