0
List alma = new ArrayList();
alma.add(new Object[] { "alma", "korte" });
alma.add(new Object[] { "alma2", "korte2" });
alma.add(new Object[] { "alma3", "korte3" });
JXPathContext context = JXPathContext.newContext(alma);
List result = context.selectNodes("????????");
System.out.println(result);

So basically what should I write into the place of question marks to see the following output:

[alma,alma2,alma3]
mre
  • 43,520
  • 33
  • 120
  • 170
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113

2 Answers2

1

I don't think it's possible. You need to put your data in some sort of container object. For example,

public class AlmaContainer {
  List<AlmaObject> alma = new ArrayList<AlmaObject>();
}

public class AlmaObject {
  String name;
  String value;
  AlmaObject(name, value) {
     this.name=name
     this.value= value
  }
}

And then you can use the following expression:

context.selectNodes("alma/@name");
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
0

That's weird, but if you can't change your initial structure you can do it in 2 steps:

Iterator<Object> iter = context.iterate(".");
while(iter.hasNext()){
    Object o=iter.next();
    JXPathContext context2 = JXPathContext.newContext(o);
    System.out.println(context2.getValue(".[1]"));
}

Outputs:

alma
alma2
alma3
JP Moresmau
  • 7,388
  • 17
  • 31