VTD Doc - looping and reading nested

Need some help here.

Have the following data…
image
want to loop through each apbillpayment and retrieve the value for each paymentkey and amount.

so I have…

VTDDocument doc = new VTDDocument("DATASTREAM1");
List <VTDElement> list = doc.selectNodes("//apbillpayment");
for (VTDElement ex : list)
{
    VTDDocument doc1 = new VTDDocument(ex.getText());
    List <VTDElement> list1 = doc1.selectNodes("//PAYMENTKEY");
    for (VTDElement el : list1)

Unfortunately when I get to the second loop i get the error…

java.lang.Exception: Cannot selectNodes() on an empty document on line #152 -> List list1 = doc1.selectNodes("//PAYMENTKEY");

I thought i needed to use ex.getText() to create the second doc and read from there but clearly it isnt reading it.

thoughts?

Need to do something like this:

VTDDocument doc = new VTDDocument("DATASTREAM1");

List <VTDElement> list = doc.selectNodes("//apbillpayment");
for (VTDElement elBillPayment : list)
{
    VTDElement elPaymentKey = elBillPayment.selectSingleNode("PAYMENTKEY");
    VTDElement elAmount = elBillPayment.selectSingleNode("AMOUNT");

    String strPaymentKey = elPaymentKey == null ? "" : elPaymentKey.getText();
    String strAmount = elAmount == null ? "" : elAmount.getText();
}

Generally if you are doing a “new VTDDocument()” within a loop of parsed XML then you are doing it wrong, unless an XML node itself contains XML as a text string which is unusually rare.

Generally you will only have a single new VTDDocument() at the start of processing, then all operations are performed on that single parsed XML document.

ok. last time I had something similar I had to create a new document. Figured it was the same.

Thanks