Forum Discussion

MRAO's avatar
MRAO
New Contributor
7 years ago

How to append a Tag in a existing XML as per count increases Dynamically through Data source

I have a requirment where i need to dynamically increase/append the tag as the count increases

 USING GROOVY

 

 

5 Replies

  • JHunt's avatar
    JHunt
    Community Hero

    Are you referring to a SoapUI Pro DataSource? If you are, please move your post to the SoapUI Pro forum.

     

    Otherwise, please be specific:

     

    What is the XML you want to update? (Post the real thing or a modified example that we can work with).

     

    When should it be updated?

     

    What should the result look like, based on the starting XML?

    • MRAO's avatar
      MRAO
      New Contributor

      HI  xml we need to manipulate. it is in soap ui free version only we need to increase the Participantcount tag dynamically using groovy when we give count as per  from csv/excel file

       

  • JHunt's avatar
    JHunt
    Community Hero

    You can turn a request like this:

     

    <request>
      <a>${a}</a>
      <b>${b}</a>
      <ParticipantCount>${age1}</ParticipantCount>
    <ParticipantCount>${age2}</ParticipantCount>
    <ParticipantCount>${age3}</ParticipantCount>
    </request>

    Into one like this:

     

    <request>
      <a>${a}</a>
      <b>${b}</a>
      ${participants}
    </request>

    Then you just need to build 'participants' with some sort of a loop across all the data.

     

     

    String s = ""
    for (Participant p : getParticipants()) {
       s += "<ParticipantCount>${p.age}</ParticipantCount>\n"
    }
    context['participantsAsXml'] = s

    Is that what you meant?

    • MRAO's avatar
      MRAO
      New Contributor

      Hi wasnt able to understand it properly can u please give a detail on it please find updated Request XML

       

      <InterfaceRQ xmlns="*****">
         <RequestHeader>
            <UserID>${#TestSuite#UserID}</UserID>
            <SessionID>${#TestSuite#SessionID}</SessionID>
            <TransactionID>${#TestSuite#TransactionID}</TransactionID>
            <SupplierCredentialsList>
               <SupplierCredentials>
                  <SupplierID>${#TestSuite#SupplierID}</SupplierID>
                  <Sequence>1</Sequence>
                  <Credentials>
                    
                     <Credential name="${#TestSuite#CredOne}" isEncrypted="${#TestSuite#Encyp}">${#TestSuite#USERNAME}</Credential>
                  
                      <OperationURLs>
                        <OperationURL operation="all">${#TestSuite#OperationURL}</OperationURL>
                     </OperationURLs>
                  </Credentials>
               </SupplierCredentials>
            </SupplierCredentialsList>
         </RequestHeader>
         <RequestBody>
           <OTA_TourAvailRQ>
            <ProcessingInformation PricingCurrency="${#TestSuite#PricingCurrency}"/>
                  <Tour>
                   <Location>
                        <Address>
                           <CountryName Code="${#TestSuite#CountryName}"/>
                        </Address>
                        <Region RegionCode="${#TestSuite#RegionCode}" />
                     </Location>
                     <Schedule StartPeriod="${#TestSuite#StartPeriod}" EndPeriod="${#TestSuite#EndPeriod}"/>
                   
                  
                      <Participant Quantity="${#TestSuite#Quantity}" Age="${#TestSuite#Age}">
                        <QualifierInfo Extension="">${#TestSuite#Extension}</QualifierInfo>
                        <!-- Value Can be Adult,Child,Infant -->
                     </Participant>
                      
                    
                  </Tour>
               </OTA_TourAvailRQ>
         </RequestBody>
      </SightSeeingInterfaceRQ>

      • nmrao's avatar
        nmrao
        Champion Level 3
        In the above xml, there is no "ParticipantCount". Is it missing?