Java HTML/XML - 如何使用XPath通過名稱計數(shù)某個標記
我們想知道如何使用XPath通過名稱計數(shù)某個標記。
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;
public class Main {
public static void main(String[] args) throws Exception {
InputSource inputSource = new InputSource("input.xml");
XPath xPath = XPathFactory.newInstance().newXPath();
String text = xPath.evaluate("/note/body", inputSource);
System.out.println(text);
}
}