I like to use Xpath to parse XML ins java, but when I am doing the same on android, XPath is not found.
any idea how it can be implemented. and also if its not possible then any other parser for android which is fast?
Thanks
Kai
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With