"TransformerException: expected location step" in android xpath

I am trying to extract data from an XML file, but I keep getting this error, and I'm not sure what I'm doing wrong.

10-23 14:20:29.250: WARN/System.err(3541): --------------- linked to ------------------ 10-23 14:20:29.250: WARN/System.err(3541): javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: A location step was expected following the '/' or '//' token. 

Here is my code:

 String pill; URL url = new URL("file:///mnt/sdcard/cpdata/cpxml.xml"); InputSource xml = new InputSource(url.openStream()); XPath xpath = XPathFactory.newInstance().newXPath(); pill = xpath.evaluate("//data/monday/p1/",xml); pills.add(pill); Log.d("PILLLLLLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", pill); tv.setText(pill + "hi"); 

And this is my XML document:

 -<data> -<monday> <p1>test1</p1> <p2>test1</p2> </monday> -<tuesday> <p1>test1</p1> <p2>test1</p2> </tuesday> -<wednesday> <p1>1.0</p1> <p2>test1</p2> </wednesday> -<thursday> <p1>test1</p1> <p2>test1</p2> </thursday> -<friday> <p1>test1</p1> <p2>test1</p2> </friday> -<saturday> <p1>test1</p1> <p2>test1</p2> </saturday> -<sunday> <p1>test1</p1> <p2>test1</p2> </sunday> 

+6
source share
1 answer

The outcome is clearly :

pill = xpath.evaluate ("// data / monday / p1 /", xml);

Used XPath expression :

  data/monday/p1/ 

ends with "/" and is therefore syntactically illegal.

Using

  pill = xpath.evaluate("//data/monday/p1",xml); 
+10
source

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


All Articles