I want to use Xpath in Android to parse XML

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

any idea how this can be implemented. and also, if this is not possible, then any other parser for android that is fast?

thanks

Kai

+4
source share
2 answers

Android XPath is available (i.e., ready to use), since the Android API level 8 (I think Android 2.2) you can find more details here .

To get started - as part of an action, try:

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

The parser can be obtained by placing the ur xml document in the res / xml folder (you may need to create this xml folder yourself). Then you can access it through:

 //Do this withon the scope of an activity, you need the activitie 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); 
+12
source

You can follow this tutorial for parsing an XML file in Android. It works very well.

+1
source

Source: https://habr.com/ru/post/1309525/


All Articles