Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;TransformerException:需要一个位置步骤;在androidxpath中_Android_Xml_Xpath - Fatal编程技术网

&引用;TransformerException:需要一个位置步骤;在androidxpath中

&引用;TransformerException:需要一个位置步骤;在androidxpath中,android,xml,xpath,Android,Xml,Xpath,我一直在尝试从xml文件中提取数据,但我一直遇到这个错误,我不确定我做错了什么 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.TransformerExcept

我一直在尝试从xml文件中提取数据,但我一直遇到这个错误,我不确定我做错了什么

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.
这是我的密码:

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");
这是我的xml文档:

-<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> 
-
- 
测试1
测试1
- 
测试1
测试1
- 
1
测试1
- 
测试1
测试1
- 
测试1
测试1
- 
测试1
测试1
- 
测试1
测试1

问题显而易见:

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

使用的XPath表达式

    data/monday/p1/
  pill = xpath.evaluate("//data/monday/p1",xml);
“/”
结尾,因此在语法上是非法的

使用

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

非常感谢你!我知道这一定很简单,我就是想不出是什么。