我想使用XPath在Android中解析XML [英] I want to use Xpath in Android to parse XML

查看:438
本文介绍了我想使用XPath在Android中解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢用XPath来解析XML的Java插件,但是当我做同样的在Android上,XPath的未找到。

I like to use Xpath to parse XML ins java, but when I am doing the same on android, XPath is not found.

任何想法如何可以实现的。并且如果它不可能那么任何其他解析器为Android是快呢?

any idea how it can be implemented. and also if its not possible then any other parser for android which is fast?

感谢

推荐答案

Android的XPath是可用的(即作为一个随时可以使用的实现)由于Android的API等级8(我认为是Android 2.2的),你可以找到更多的信息< A HREF =htt​​p://developer.android.com/reference/javax/xml/xpath/package-summary.html>这里。

Android XPath is available (i.e. as a ready-to-use implementation) since Android API Level 8 (I think thats Android 2.2) you can find more information here.

为让你开始 - 一个活动尝试的范围之内:

To get you started - within the scope of an activity try:

XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "myNode";
NodeList nodes = (NodeList) xpath.evaluate(expression, parser, XPathConstants.NODESET);

在分析器可以通过将UR XML文件到您的RES / XML文件夹中获得(您可能必须创建一个XML文件夹自己)。然后,您可以通过访问:

The "parser" can be obtained by putting ur xml document into your res/xml folder (you might have to create that xml folder yourself). Then you can access it via:

//Do this withon the scope of an activity, you need the activitie's context!
Resources res = getResources();
//Get the xml file
//this is how you access the content of the xml folder 
//you previously created in the res folder
parser = res.getXml(R.xml.yourxmlfile);

这篇关于我想使用XPath在Android中解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆