Ive been trying to pull data from an xml file but i keep getting this error and im not sure what im 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>
The isssue is obvious:
pill = xpath.evaluate("//data/monday/p1/",xml);
The XPath expression used:
data/monday/p1/
ends with "/"
and thus is syntactically illegal.
Use:
pill = xpath.evaluate("//data/monday/p1",xml);
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