Layer7 API Management

  • 1.  Is there any assertion for  converting a array to  XML tags

    Posted Feb 23, 2015 03:54 PM

    Array of {1,2,3,4,5,6}  to

     

     

    <name>1</name>

    <name>2</name>

    <name>3</name>

    <name>4</name>

    <name>5</name>

    <name>6</name>


    We dont know the size of array.


    How can this type of transformations done in Layer7?





  • 2.  Re: Is there any assertion for  converting a array to  XML tags

    Broadcom Employee
    Posted Feb 23, 2015 04:27 PM

    Yes, you can use split variable and then run assertion  for each item…

     

     

     

    Within the run assertion for each item you can build a variable to then be placed inside a another variable.  Then within the run assertions for each item build out a variable with the tags that you want to surround it.  The value within the tag would be *.current from the run each assertion current run through of the value from the split variable.  It will know how many times the value appears.

     

     

    [Google]<https://plus.google.com/CATechnologies>[Slideshare]<http://www.slideshare.net/cainc>



  • 3.  Re: Is there any assertion for  converting a array to  XML tags

    Posted Feb 24, 2015 10:49 AM

    A sample is more appreciated

    I have sent an email to you from my corp id



  • 4.  Re: Is there any assertion for  converting a array to  XML tags
    Best Answer

    Broadcom Employee
    Posted Feb 24, 2015 05:12 PM
      |   view attached

    We have attached a sample policy that should accomplish what you are looking for. Output expected:

    <names><name>1</name><name>2</name><name>3</name><name>4</name><name>5</name><name>6</name></names>

    Attachment(s)

    zip
    arrayOfXMLTags.xml.zip   711 B 1 version


  • 5.  Re: Is there any assertion for  converting a array to  XML tags

    Posted Apr 01, 2015 09:27 PM
      |   view attached

    You don't even need to use Run For Each Item assertion if the following conditions hold:

     

    1. The array will never be empty (or it is OK in this case to emit a single empty element)

    2. The items in the array will never contain XML metacharacters (such as < > &) that require escaping

     

    Then you can just use the join syntax built into the Gateway's string interpolation feature, where you can include a vertical bar after the variable name followed by a custom delimiter to use for joining multivalued variable items when interpolating into a string.  You can change the template response to the following and delete the Run For Each Item assertion:

     

    <names>

    <name>${array|</name><name>}</name>

    </names>

     

    I've attached an edited sample policy showing this.

    Attachment(s)