javamemidlet中的Web服务
我正在尝试使用web服务制作midlet(国家/地区详细信息)。我不确定如何显示结果,其他一切似乎都很好 以下是获取输入信息和结果的代码(我无法获取): 在运行窗口中,我看到它获取以下信息:javamemidlet中的Web服务,java,web-services,java-me,Java,Web Services,Java Me,我正在尝试使用web服务制作midlet(国家/地区详细信息)。我不确定如何显示结果,其他一切似乎都很好 以下是获取输入信息和结果的代码(我无法获取): 在运行窗口中,我看到它获取以下信息: <NewDataSet> <Table> <Name>Norway</Name> <CountryCode>no</CountryCode> <Currency>Kroner</Curren
<NewDataSet>
<Table>
<Name>Norway</Name>
<CountryCode>no</CountryCode>
<Currency>Kroner</Currency>
<CurrencyCode>NOK</CurrencyCode>
</Table>
<Table>
<Name>Norway</Name>
<CountryCode>no</CountryCode>
<Currency>Kroner</Currency>
<CurrencyCode>NOK</CurrencyCode>
</Table>
</NewDataSet>
挪威
不
克罗纳
诺克
挪威
不
克罗纳
诺克
编辑
我已经使用了此代码,现在可以正常工作了:
task = new SimpleCancellableTask();
task.setExecutable(new org.netbeans.microedition.util.Executable() {
public void execute() throws Exception {
country CWS = new country_Stub();
String country = FieldCountry.getString();
String result = CWS.getCurrencyByCountry(country);
if (list != null)
{list = null; }
String name = result.substring(result.indexOf("<Name>")+6, result.indexOf("</Name>"));
String countryc = result.substring(result.indexOf("<CountryCode>")+13, result.indexOf("</CountryCode>"));
String currency = result.substring(result.indexOf("<Currency>")+10, result.indexOf("</Currency>"));
String currencyc = result.substring(result.indexOf("<CurrencyCode>")+14, result.indexOf("</CurrencyCode>"));
getList().append("Country name: ", null);
getList().append(name, null);
getList().append("Country code: ", null);
getList().append(countryc, null);
getList().append("Country currency: ", null);
getList().append(currency, null);
getList().append("Country currency code: ", null);
getList().append(currencyc, null);
}
});
task=newsimplecancelllabletask();
task.setExecutable(new org.netbeans.microedition.util.Executable()){
public void execute()引发异常{
国家/地区CWS=新的国家/地区存根();
String country=FieldCountry.getString();
字符串结果=CWS.getCurrencyByCountry(国家);
如果(列表!=null)
{list=null;}
字符串名称=result.substring(result.indexOf(“”+6,result.indexOf(“”));
字符串countryc=result.substring(result.indexOf(“”+13,result.indexOf(“”));
字符串currency=result.substring(result.indexOf(“”+10,result.indexOf(“”));
字符串currencyc=result.substring(result.indexOf(“”+14,result.indexOf(“”));
getList().append(“国家名称:”,null);
getList().append(名称,null);
getList().append(“国家代码:”,null);
getList().append(countryc,null);
getList().append(“国家货币:”,空);
getList().append(货币,空);
getList().append(“国家货币代码:”,空);
getList().append(currencyc,null);
}
});
您已经获得了XML文件。
现在您只需要使用一个简单的XML解析器来解析XML。
有一些很好的XML解析器可用于J2ME。
你可以看看
KXML是一个很好的选择,因为有很多关于KXML的文档可用。我已经试着阅读了有关解析的内容,但它仍然让我感到困惑。我通过查看另一个类似的代码使程序正常工作。所以我不确定我使用了什么样的解析?无论如何,我很高兴它能工作(编辑后的代码)
task = new SimpleCancellableTask();
task.setExecutable(new org.netbeans.microedition.util.Executable() {
public void execute() throws Exception {
country CWS = new country_Stub();
String country = FieldCountry.getString();
String result = CWS.getCurrencyByCountry(country);
if (list != null)
{list = null; }
String name = result.substring(result.indexOf("<Name>")+6, result.indexOf("</Name>"));
String countryc = result.substring(result.indexOf("<CountryCode>")+13, result.indexOf("</CountryCode>"));
String currency = result.substring(result.indexOf("<Currency>")+10, result.indexOf("</Currency>"));
String currencyc = result.substring(result.indexOf("<CurrencyCode>")+14, result.indexOf("</CurrencyCode>"));
getList().append("Country name: ", null);
getList().append(name, null);
getList().append("Country code: ", null);
getList().append(countryc, null);
getList().append("Country currency: ", null);
getList().append(currency, null);
getList().append("Country currency code: ", null);
getList().append(currencyc, null);
}
});