JDOM-XPath: Can't get the second value in a collection
I'm pretty confused about this one. Given the following xml:
<sch:eventList>
   <sch:event>
      <sch:eventName>Event One</sch:eventName>
      <sch:locationName>Location One</sch:locationName>
   </sch:event>
   <sch:event>
      <sch:eventName>Event Two</sch:eventName>
      <sch:locationName>Location Two</sch:locationName>
   </sch:event>
</sch:eventList>
When using JDOM using the following code:
  XPath eventNameExpression = XPath.newIn开发者_如何转开发stance("//sch:eventName");
  XPath eventLocationExpression = XPath.newInstance("//sch:eventLocation");
  XPath eventExpression = XPath.newInstance("//sch:event");
  List<Element> elements = eventExpression.selectNodes(requestElement);
  for(Element e: elements) {
      System.out.println(eventNameExpression.valueOf(e));
      System.out.println(eventLocationExpression.valueOf(e));
  }
The console shows this:
 Event One
 Location One
 Event One
 Location One
What am I missing?
Don't use '//' it starts always searching at the root node. Use e.g. './sch:eventName' it is relative to the current node.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论