从 Android 应用程序查询远程 XML 文件
我正在开发一个应用程序,需要从服务器上存储的 XML 文件中检索信息。
我使用 SAX 编写了一个解析器类,它读取数据并将其弹出到一个对象中,然后我可以根据需要访问该对象。
我将如何查询数据,例如搜索特定值,然后仅读取相关元素。在服务器端,我可以轻松编写 XQuery 以返回所需的元素,但是我不确定如何从我的应用程序中执行此操作。
是否可以在服务器端执行查询,然后解析生成的 XML 文件?
我有点失落。如果有人能指出我正确的方向,我将非常感激!
I am developing an application that is required to retreive information from an XML file stored on a server.
I have written a parser class, using SAX, that reads in the data and pops it into an object which I can then access as required.
How would I go about querying the data, for instance searching for particular values and then only reading in the relevant elements. Server side, I can easily write an XQuery in order to return the required elements, however I am unsure how to do this from my application.
Is it possible to execute querys server side and then parse the resulting XML file?
I'm a little lost. If anyone can point me in the right direction, I'd be very grateful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在 Android 2.2 或更高版本上进行开发,则可以利用 javax.xml.xpath 的功能(在 API 级别 8 中引入)。
如果您正在 Android 2.1 或更早版本上进行开发,那么服务器端过滤器(如您所建议的:xquery 或 xpath)将是最好的,否则您应该硬过滤您的 xml 数据,或者将其全部包装到
列表
,并过滤该列表。这两种方式都非常消耗资源。在我看来,如果一次处理大量数据,但只显示其中的一小部分,服务器端过滤会更好(即使它需要多个http请求:在更改数据集时这是不可避免的)。
If you are developing on Android 2.2 or later, you can take advantage of the
javax.xml.xpath
's functionality (introduced in API level 8).If you are developing on Android 2.1 or earlier, the server side filter (as you suggested: xquery or xpath) would be the best, otherwise you should hard-filter your xml data, or wrap all of it into java Objects in a
List<?>
, and filter that list. Both ways are quite resource-eating.In my opinion, if handling huge amount of data at once, but displaying just a small part of it, the server side filtering is better (even though it needs multiple http requests: on changing data sets this is unevitable anyway).