解析来自 Android 的 XML RPC 结果
我是否需要将 XML 结果放入临时本地 xml 文件中,然后从那里进行解析?我正在尝试使用 Foxrate 的 RPC API 创建“简单”货币转换,网址为 http://foxrate.org/ ,我一直在努力弄清楚下一步该做什么。我在这里遵循的 XML 示例很好,其中一些示例超出了我的需要(我认为)。我正在使用 code.google 中的 Android XML RPC 库,因此我可以从以下内容开始。
uri = URI.create("http://foxrate.org/rpc/");
client = new XMLRPCClient(uri);
Object FoxResult = null;
try {
FoxResult = client.call("foxrate.currencyConvert", sourceCurrency, targetCurrency, conversionValue);
Log.d("XMLRPC Test", "result conversion" );
} catch (XMLRPCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("XMLRPC Test", "Error", e);
}
但然后呢?在过去的几天里,我一直在试图弄清楚如何将结果结构分开并将它们放入我可以使用的变量中。我是否使用 DOM 或 SAX 来提取我需要的信息?我是否需要编写一个事件处理程序,如此处所述,http://www. anddev.org/web_services_-_an_xml-rpc_client_for_android-t646.html,为此?我发现有大量信息,但都有不同的解决方案。
服务器的响应是这样的:
<params>
<param>
<value>
<struct>
<member>
<name>flerror</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>amount</name>
<value>
<double>50.36</double>
</value>
</member>
<member>
<name>message</name>
<value>
<string>"2/9/2007"</string>
</value>
</member>
</struct>
</value>
</param>
</params>
感谢您的指导!
Do I need to place the XML result into a temporary local xml file and then parse from there? I'm trying to create a 'simple' currency conversion, using Foxrate's RPC API at http://foxrate.org/, and I'm stuck at trying to figure out what to do next. The XML examples that I've followed here are good, some are over the top for what I need (I think). I'm using the Android XML RPC library from code.google, so I can start with the below.
uri = URI.create("http://foxrate.org/rpc/");
client = new XMLRPCClient(uri);
Object FoxResult = null;
try {
FoxResult = client.call("foxrate.currencyConvert", sourceCurrency, targetCurrency, conversionValue);
Log.d("XMLRPC Test", "result conversion" );
} catch (XMLRPCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("XMLRPC Test", "Error", e);
}
But then what? For the past couple days I've been trying to figure out how to pull the result struct apart and put them into variables I can use. Do I use DOM or SAX to pull out the information I need? And do I need to write an event Handler as mentioned here, http://www.anddev.org/web_services_-_an_xml-rpc_client_for_android-t646.html, for this? I've found that there's loads of information, but all with different solutions.
The response from the server is something like this:
<params>
<param>
<value>
<struct>
<member>
<name>flerror</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>amount</name>
<value>
<double>50.36</double>
</value>
</member>
<member>
<name>message</name>
<value>
<string>"2/9/2007"</string>
</value>
</member>
</struct>
</value>
</param>
</params>
Thanks for any direction!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
您需要对异常和缺失值进行适当的检查,但对于 struct 类型,它返回一个 Map。
Try this:
You'll need to do the appropriate checking for exceptions and missing values, but for
struct
types it returns a Map.