I have the following XML:
<Details>
<Detail>
<name>Detail one</name>
<id>001</id>
</Detail>
<Detail>
<name>Detail two</name>
<id>002</id>
</Detail>
</Details>
I request this by name to get the identifier using a service XQuerywith a tag Java:
public String getIdByName(String detailName) {
final String detail_Name = detailName;
return engine.new Query<String>(DETAILS_COLLECTION) {
@Override
protected String query(Collection collection) throws Exception {
XQueryService service = queryService();
ResourceSet resourceSet = service.query(
format("//Details/Detail[name='%s']" +
"/id/text()"
, StringEscapeUtils.escapeXml(detailName)
));
List<String> ids = newArrayList();
for (String resource : new IterableStringResources(resourceSet)) {
instanceLocations.add(resource);
}
return ids.get(0);
}
}.execute();
}
This method correctly returns the identifier for this section XMLnamed "Detail One":
<Detail>
<name>Detail one</name>
<id>001</id>
<Detail>
But it returns no values ββfor the second named "Detail two":
<Detail>
<name>Detail two</name>
<id>002</id>
</Detail>
What could be the reason for this?
source
share