Array of Array in XML Response
Hello. I am using an XML Response as a DataSource. It has an array of books, and I can process the array by changing books[1] to books, so that it will iterate through each book.
Each book also has chapters, so I'm trying to get the chapters that are specific to each book. I have a Book DataSource (XML) and a Chapters DataSource (XML), but I cannot figure out how to get the chapters that are specific only to the book I am processing.
It seems like there would be an easy way to get the row index so that I can do something like:
books[rowIndex]:chapters. In other words...get all of the chapters for book[1], then book[2], etc.
Any help is appreciated!
Hi,
I think I understand what you're trying to do, but the description isn't quite clear in places.
My take: You have a Books datasource that you are iterating over. You have a second datasource called chapters. Based on my reading, you want to pull out the chapters from the second datasource for a given book.
One part that is confusing me, is that if Books and Chapters are both datasource steps or "sources of data" rather than datasources in a SoapUI sense.
If you do have two datasource steps, maybe frame your test like...
In this method, you have to iterate over each book, but for each book you have to iterate over every chapter and for each chapter, check whether it belongs to the book of interest.
If, you just have two distinct lumps of XML, one for Books and one for Chapters, and you've already managed to iterate Books, then you ought to look at XML Holder.
You can import XML Holder by this...
import com.eviware.soapui.support.XmlHolder;
to then populate XML Holder you do something like...
chaptersXmlHolder = new XmlHolder(chaptersVariable); chaptersXmlHolder.namespaces["ns1"] = theUrlForNs1Namespace;
You can then (hopefully) directly access the chapters using the getNodeValue method on your XML holder.
keyValuePath = "//${bookName}/${chapters}[1]"; firstChapterForBook = chaptersXmlHolder.getNodeValue(keyValuePath);
Without a concrete example of the data you're working with, it's not possible to provide specific answers.
You should look at this SmartBear link on XML Holder .