简体   繁体   English

JMeter XPath提取器2.11

[英]JMeter XPath Extractor 2.11

I am trying to extract several value from my xml response, regular expression extractor doesn't seem to work. 我正在尝试从xml响应中提取几个值,正则表达式提取器似乎不起作用。

I want to try this but I am an XPath Newbie and I know enough about XML. 我想尝试一下,但是我是XPath新手,并且对XML足够了解。 A snippet of the xml code I am trying to do an extract from. 我试图从中提取的xml代码片段。

<entry>
    <string>equipmentName</string>
    <string>JPP</string>
</entry>

What I cant understand in all the docs I read is what the XPath query? 在我阅读的所有文档中,我无法理解的是XPath查询是什么?

Is there anything anyone can suggest? 有什么可以建议的吗? W need to extract the JPP part of this snippet. W需要提取此代码片段的JPP部分。

There are some possible XPath queries you can use to get JPP , depending on how you want to identify the element. 您可以使用一些可能的XPath查询来获取JPP ,具体取决于您要如何标识元素。 For example, we can identify JPP element as the last <string> child of <entry> : 例如,我们可以将JPP元素标识为<entry>的最后一个<string>子元素:

//entry/string[last()]

and of course, you can also identify the element by it's value like so : 当然,您也可以像这样通过其值来标识元素:

//entry/string[.='JPP']

...while this is possible, I don't think selecting element by value is desirable here because you have to know the value in the first place. ...虽然这是可能的,但我认为这里不希望按值选择元素,因为您必须首先了解值。

XPath is another topic that you can learn independently, and later use it on various platform including JMeter. XPath是您可以独立学习的另一个主题,以后可以在包括JMeter在内的各种平台上使用。 Use an XPath tester of your choice, put random XML and some random XPath, and see what the XPath return : 使用您选择的XPath测试器,放置随机XML和一些随机XPath,然后查看XPath返回什么:

*) side note: w3schools doesn't have relation to the W3C. *)旁注:w3schools与W3C没有关系。 I recommend this just because the tutorial is easy to follow and concise, to get you started with XPath 我之所以建议这样做,是因为该教程易于理解和简洁,可以帮助您开始使用XPath。
**) No particular reason for using this XPath tester, just happened to be the first tester I found. **)使用此XPath测试仪没有特别的原因,只是我发现的第一个测试仪。

If you looking for "JPP" where parent string is "equipmentName" your XPath query should look as follows: 如果在父字符串为“ equipmentName”的情况下查找“ JPP”,则XPath查询应如下所示:

//entry/string[text()='equipmentName']/../string[2]/text()

See XPath 1.0 Language Reference and Using the XPath Extractor in JMeter guides for more details. 有关更多详细信息,请参见JMeter指南中的XPath 1.0语言参考使用XPath提取器

NB above XPath query is for reference only, it may or may not work on your actual data, especially if there are namespaces defined, if it doesn't play for your - update your question with full XML response. 注意:以上XPath查询仅供参考,它可能对您的实际数据起作用,也可能不起作用,尤其是在定义了名称空间的情况下,如果它不适用于您-请使用完整的XML响应更新您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM