1

Мне нужно получить те объекты, атрибуты которых равны "q" и вывести все названия тайтлов, у которых этот атрибут таков

<title name="q">A1</title>
<title name="sss">A2</title>
<title name="q">A3</title>


XPathExpression exprLang = xpath.compile("//title");
NodeList listLang = (NodeList) exprLang.evaluate(doc, XPathConstants.NODESET);

for (int i = 0; i <  listLang.getLength(); i++) {
  if (listLang.item(i).getAttributes("q")) {
    System.out.println(listLang.item(i).getTextContent());
  }
}

1 ответ 1

3

Поиск с учётом атрибута: //title[@name='q']

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.