Layer7 API Management

  • 1.  Iterating XML Array elements

    Posted Mar 09, 2015 11:52 AM


    HI Earlier I have received help in iterating a comma separated String.

     

    I  also have one more complext and similar requirement

     

    If we have multiple XML Elements of same type.

     

     

    if it is single I am able to do XPath and get that element. But if we have array of similar XML elements how to extract them.

     

    Help is much appreciated with an example.



  • 2.  Re: Iterating XML Array elements

    Posted Mar 11, 2015 07:56 AM

    Hi. You can still you xpath to extract multiple elements of the same type.



  • 3.  Re: Iterating XML Array elements

    Posted Mar 11, 2015 12:33 PM

    Say lets take an example in java if I have array of objects

    we can iterate each object and get its child variables

     

    In layer7 we can only do for one array.

    if we can do it please let me know a sample



  • 4.  Re: Iterating XML Array elements

    Posted Mar 24, 2015 12:22 PM
      |   view attached

    Lets say we have the following xml:

     

    <root>

        <element1>

              <element2>sometext</element2>

        </element1>

        <element1>

              <element2>somemoretext</element2>

        </element1>

    </root>

     

    I presume you want to access the element2 nodes. You can do this with the following XPATH: /root/element1/element2. This will create a series of multivalued variables:

    ${requestXpath.count}: The number of found nodes, in this case 2

    ${requestXpath.results}: MultiValued variable that contains the full nodes, with enclosing tags, eg: <element2>sometext</element2>, <element2>somemoretext</element2>

    ${requestXpath.elements}: Multivalued variable that contains the text of the selected nodes, eg: sometext, somemoretext

     

    You can use any of those variables that suit you with a "Run assertions for each item" folder assertion which will apply all the assertions contained in that folder to each element of the multivalued variable.

     

    The policy attached to this message is a sample that demonstrates the logic with a simple xml.

     

    I hope you find this helpful.

    Attachment(s)

    zip
    loopForEachXML.xml.zip   1 KB 1 version