teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード修正

2021/12/30 18:06

投稿

jimbe
jimbe

スコア13355

answer CHANGED
@@ -39,9 +39,9 @@
39
39
 
40
40
  static List<String> getTextContentList(Document document, String expression) throws XPathExpressionException {
41
41
  XPathExpression expr = XPathFactory.newInstance().newXPath().compile(expression);
42
+ NodeList nodeList = (NodeList)expr.evaluate(document, XPathConstants.NODESET);
42
43
 
43
44
  List<String> list = new ArrayList<>();
44
- NodeList nodeList = (NodeList)expr.evaluate(document, XPathConstants.NODESET);
45
45
  for(int i=0; i<nodeList.getLength(); i++) {
46
46
  list.add(((Element)nodeList.item(i)).getTextContent());
47
47
  }