I am not able to make this code crop work, mistakes are not but the result is not the wished one
Example block xml:
<block>
<id_block>2147483641</id
_block>
<name_block>2147483641</name_block>
<size>2147483641</size>
<last_offset>2147483641</last_offset>
<last_byte_write>2147483641</last_byte_write>
<delete>
<offset_init>2147483641</offset_init>
<offset_fin>2147483641</offset_fin>
</delete>
<delete>
<offset_init>2147483655</offset_init>
<offset_fin>2147483667</offset_fin>
</delete>
</block>
code which is not working:
resultsBlock contains the 10 blocks and he is a XMLRESULT
...
XmlValue valueBlock = resultsBlock.next();
while (valueBlock != null) {
String nameQ = "distinct-values(/storage/block/id_block)";
long name = 0;
String sizeQ = "distinct-values(/storage/block/size)";
long size = 0;
String lastOffsetQ = "distinct-values(/storage/block/last_offset)";
long lastOffset = 0;
String nameBlockFileQ = "distinct-values(/storage/block/name_block)";
String nameBlockFile = "";
String lastByteWriteQ = "distinct-values(/storage/block/last_byte_write)";
long lastByteWrite = 0;
String deleteQ = "distinct-values(/storage/block/delete)";
XmlQueryContext documentContext = mgr.createQueryContext();
documentContext.setReturnType(XmlQueryContext.DeadValues);
ArrayList listDelete = new ArrayList();
Block block;
XmlQueryExpression nameExpr = mgr.prepare(nameQ, documentContext);
XmlResults nameResults = nameExpr.execute(valueBlock, documentContext);
name = Long.parseLong(nameResults.next().asString());
XmlQueryExpression sizeExpr = mgr.prepare(sizeQ, documentContext);
XmlResults sizeResults = sizeExpr.execute(valueBlock, documentContext);
size = Long.parseLong(sizeResults.next().asString());
XmlQueryExpression lastOffsetExpr = mgr.prepare(lastOffsetQ, documentContext);
XmlResults lastOffsetResults = lastOffsetExpr.execute(valueBlock, documentContext);
lastOffset = Long.parseLong(lastOffsetResults.next().asString());
XmlQueryExpression nameBlockFileExpr = mgr.prepare(nameBlockFileQ, documentContext);
XmlResults nameBlockFileResults = nameBlockFileExpr.execute(valueBlock, documentContext);
nameBlockFile = nameBlockFileResults.next().asString();
XmlQueryExpression lastByteWriteExpr = mgr.prepare(lastByteWriteQ, documentContext);
XmlResults lastByteWriteResults = lastByteWriteExpr.execute(valueBlock, documentContext);
lastByteWrite = Long.parseLong(lastByteWriteResults.next().asString());
XmlQueryExpression deleteExpr = mgr.prepare(deleteQ, documentContext);
XmlResults deleteResults = deleteExpr.execute(valueBlock, documentContext);
block = new Block(lastByteWrite, lastOffset, listDelete, name, nameBlockFile, size);
listaBlocchi.add(block);
// Ricavo il singolo blocco
valueBlock = resultsBlock.next();
}
wished result: an ArrayList containing the ten blocks
obtained result: an ArrayList containing 10 blocks with the values of the first block
could you show me where I make a mistake?
|