Reputation: 177
I want to extract the contents of SFDCProductList in a variable, which is an array.
How to do this?
I have this following xml:
.
.
.
10000
Thank You! Your request has been successfully executed. Code PIM 10000
sgfsuifg
sjkfbksgfsudf
</SFDCProduct>
</SFDCProductList>
<SFDCProductList>
.
.
.
</SFDCProductList>
<SFDCProductList>
.
.
.
</SFDCProductList>
<TransportInformation>
.
.
.
</TransportInformation>
</EnhancedServicePrequalResponse>
<EnhancedServicePrequalResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Code>10000</Code>
<Message>Thank You!</Message>
<SFDCProductList>
<SFDCProduct>
<OfferName>XYZ</OfferName>
<OfferDisplayName>New Offer</OfferDisplayName>
<OfferType>New</OfferType>
<EndDate>2021-02-16</EndDate>
<OfferLineItemList>
<OfferLineItem>
<OfferLineItemCategory>Transport Service</OfferLineItemCategory>
<OfferLineItemName>transport</OfferLineItemName>
</OfferLineItem>
<OfferLineItem>
<OfferLineItemCategory>Device</OfferLineItemCategory>
<OfferLineItemName>Billing</OfferLineItemName>
</OfferLineItem>
</OfferLineItemList>
<TransportName>BR</TransportName>
</SFDCProduct>
</SFDCProductList>
<SFDCProductList>
<SFDCProduct>
<OfferName>Upgrade</OfferName>
<OfferDisplayName>Upgrade</OfferDisplayName>
<OfferType>Upgrade</OfferType>
<EndDate>2021-02-16</EndDate>
<OfferLineItemList>
<OfferLineItem>
<OfferLineItemCategory>Transport</OfferLineItemCategory>
<OfferLineItemName>Billing</OfferLineItemName>
</OfferLineItem>
<OfferLineItem>
<OfferLineItemCategory>Device</OfferLineItemCategory>
<OfferLineItemName>Billing</OfferLineItemName>
</OfferLineItem>
</OfferLineItemList>
<TransportName>JR</TransportName>
</SFDCProduct>
</SFDCProductList>
<TransportInformation>
<TransportFeasibilityParameter>
<AvailabilityFlag>true</AvailabilityFlag>
<BusinessAvailabilityFlag>true</BusinessAvailabilityFlag>
<TransportName>BR</TransportName>
</TransportFeasibilityParameter>
<TransportFeasibilityParameter>
<AvailabilityFlag>true</AvailabilityFlag>
<BusinessAvailabilityFlag>true</BusinessAvailabilityFlag>
<TransportName>JR/TransportName>
</TransportFeasibilityParameter>
</TransportInformation>
</EnhancedServicePrequalResponse>
I tried with xpath extractor but its not storing it in a variable.
I have successfully extracted the SFDCProductlist with Boundary extractor but as its an array i only want that SFDCProductlist which has "New" keyword in the element .
The beanshell Script:
int SFDCProduct_matchNr =vars.get("SFDCProduct_matchNr");
String list="SFDCProduct"+"_"+"SFDCProduct_matchNr";
int SFDCProduct_matchNrvalue=SFDCProduct_matchNr-1;
vars.put("SFDCProduct_matchNr", "SFDCProduct_matchNrvalue");
vars.put("sfdc", "list");enter code here
But still its not assigning the sfdc with SFDCProduct_1 value??
Upvotes: 3
Views: 8342
Reputation: 1999
From you response code, seems like there are more than one product list.
To fetch all, you need to set Match No. to -1 in the Boundary extractor. Then, use the vars.get{"Product_List_1"} to fetch specific one.
If you need all in one variable, one way, is to combine different array list.
Upvotes: 1
Reputation: 168227
Without seeing the full XML response we cannot come up with an exact solution, however for XML response types it makes sense to stick to XPath Extractor
The relevant XPath query should be something like: //SFDCProductList
- it will basically return everything under <SFDCProductList>
tag:
If it doesn't - double check your XPath expression using "XPath Tester" mode of the View Results Tree listener, in some cases you might need to:
Use Tidy
box if the response is not valid XML/XHTMLReferences:
Upvotes: 1
Reputation: 58902
To extract contents inside specific boundaries you can use Boundary Extractor:
Choose as Left boundary and </SFDCProductList>
as Right boundary.
Put new variable name in Name of created variable
as productList and use it later as ${productList}
or vars.get("productList")
inside a JSR223 script.
Allows the user to extract values from a server response using left and right boundaries. As a post-processor, this element will execute after each Sample request in its scope, testing the boundaries, extracting the requested values, generate the template string, and store the result into the given variable name.
Upvotes: 2