xpath - 根据元素中的特定字符串从jmeter中的xml响应中提取元素

标签 xpath xml-parsing jmeter

enter image description here enter image description here enter image description here我想在一个变量中提取 SFDCProductList 的内容,它是一个数组。
这该怎么做?

我有以下 xml:

.
.
.
10000 谢谢你!您的请求已成功执行。代码 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>

我尝试使用 xpath 提取器,但它没有将它存储在变量中。

我已经使用边界提取器成功提取了 SFDCProductlist,但作为一个数组,我只想要在元素中包含“New”关键字的 SFDCProductlist。
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??

最佳答案

要提取特定边界内的内容,您可以使用 Boundary Extractor :

选择为左边界和 </SFDCProductList>作为右边界。

将新变量名放入 Name of created variable作为 productList 并稍后使用它作为 ${productList}vars.get("productList")在 JSR223 脚本中。

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.

关于xpath - 根据元素中的特定字符串从jmeter中的xml响应中提取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52303877/

相关文章:

c++ - XML 解析器 - 数据绑定(bind) C++ 生成器

performance - 合并两个在不同机器上运行的测试报告的*.jtl文件

javascript - 如何避免将数组转换为逗号分隔的字符串?

xml - xpath - 具有属性问题的谓词

java - 使用 DOM 解析器在 xml java 中使用子节点搜索特定节点

javascript - $x() 函数未在 Chrome 扩展、内容脚本中定义

python - Xpath - 即使我只得到 1 个元素 - 检查器工具显示 7

java - 如何从 ADF 中的 Java 类创建数据控件和 View 对象

amazon-web-services - JMeter 脚本中的 S3 访问

java - StaX 解析 : Transformer. 变换方法自动移动光标,并不总是很好