Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.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
Java 选择特定条件后的下一个节点_Java_Parsing_Xml Parsing_Jsoup - Fatal编程技术网

Java 选择特定条件后的下一个节点

Java 选择特定条件后的下一个节点,java,parsing,xml-parsing,jsoup,Java,Parsing,Xml Parsing,Jsoup,我试图在下面的html中选择span标记之后的下一个节点值(编号4)。我该怎么做 <tr valign="top"> <td></td> <td><a href="#"> 1 </a></td> <td><a href="#"> 2 </a></td> <td><span> 3 </span><

我试图在下面的html中选择span标记之后的下一个节点值(编号4)。我该怎么做

<tr valign="top">
    <td></td>
    <td><a href="#"> 1 </a></td>
    <td><a href="#"> 2 </a></td>
    <td><span> 3 </span></td>
    <td><a href="#"> 4 </a></td>
    <td><a href="#"> 5 </a></td>
    <td><a href="#"> 6 </a></td>
</tr>

3.
文档:

final String html = "<tr valign=\"top\">\n"
        + "    <td></td>\n"
        + "    <td><a href=\"#\"> 1 </a></td>\n"
        + "    <td><a href=\"#\"> 2 </a></td>\n"
        + "    <td><span> 3 </span></td>\n"
        + "    <td><a href=\"#\"> 4 </a></td>\n"
        + "    <td><a href=\"#\"> 5 </a></td>\n"
        + "    <td><a href=\"#\"> 6 </a></td>\n"
        + "</tr>";

Document doc = Jsoup.parse(html);

Element nextToSpan = doc.select("span").first().nextElementSibling();
doc.select("span") // Select the span-tags of doc
    .first()    // retrieve the first one
    .nextElementSibling();  // Get the element that's next to it