Forum Discussion

brianchi73's avatar
Occasional Visitor
4 years ago

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...
  • ChrisA's avatar
    4 years ago



    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...




    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 .