Rea*_*oid 11
从Android API Level 8(我认为是Android 2.2)开始,Android XPath可用(即作为即用型实现),您可以在此处找到更多信息.
为了帮助您入门 - 在活动范围内尝试:
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "myNode";
NodeList nodes = (NodeList) xpath.evaluate(expression, parser, XPathConstants.NODESET);
Run Code Online (Sandbox Code Playgroud)
可以通过将ur xml文档放入res/xml文件夹来获取"解析器"(您可能必须自己创建该xml文件夹).然后你可以通过以下方式访问它
//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);
Run Code Online (Sandbox Code Playgroud)