0

I need to get every operator_id tags attribute @name in group tag with @title attribute equals some string, an example below fails to do this:

List list = doc.selectNodes("//root//menu//group[@title=" + menuTitle + "]//operator_id//@name");

XML Structure:

  <group id="980" title="Переводы" image="" sh_n="1" enable="1" visible="0" image_bg="" type="">
  <operator_id id="10000047" name="Перевод физ лицу" image="individual.png" sh_n="1" enable="1" visible="1" /> 
  <operator_id id="10000048" name="Перевод юр лицу" image="organizations.png" sh_n="1" enable="1" visible="1" /> 
  <operator_id id="10000078" name="Перевод внутри банка" image="innerbank.png" sh_n="1" enable="1" visible="1" /> 
  <operator_id id="10000049" name="Налоговый платеж" image="taxes1.png" sh_n="1" enable="1" visible="1" /> 
  </group>

What am I doing wrong?

1 Answer 1

2

I'm not an XPath expert by any means, but I don't think you want to use double-slashes all the way through your query. Have you tried:

List list = doc.selectNodes(
   "//root/menu/group[@title=" + menuTitle + "]/operator_id/@name");

? Even the // at the start can be just / if it's really meant to be the root element.

Additionally, I suspect you should add quoting for the value, e.g.

List list = doc.selectNodes(
   "//root/menu/group[@title='" + menuTitle + "']/operator_id/@name");

or

List list = doc.selectNodes(
   "//root/menu/group[@title=\"" + menuTitle + "\"]/operator_id/@name");

Those would be more like the samples in the XPath specification.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I've already tried it out and it works - thank U for response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.