i have an xml that looks this way
<Quiz>
<Inhalt Frage="test" number="1" />
<Inhalt Frage ="test2" number=2"/>
</Quiz>
Now, in android i want to parse this xml in that way, that the result show me the content of "Frage" for the number 2. I have tried to parse it this way, but i always get a nullexception error:
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr= xpath.compile("//Frage[@number=2]/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
einga= nodes.item(0).getNodeName();
Would be great, if someone could help me with this. Thank you :-)
/missing before the@in @Stephane's suggestion. In regard to learning XPath: please don't use w3schools, unless you want to have to unlearn their mistakes later. (See w3fools.com) Instead try zvon.org/xxl/XPathTutorial/General/examples.html