如何检查 XML 响应是否包含模式?
How can I check if an XML response contains a pattern?
我的回复如下。
<reply>
<status description="Error: REST call to http://localhost:8090/nmradapter/nmr/getICCIDDetails/123 failed: Server returned HTTP response code: 503 for URL: http://localhost:8090/nmradapter/nmr/getICCIDDetails/123 " />
</reply>
我已经使用 XML 解析器来解析响应,并且我需要通过响应检查状态描述是否包含响应代码 503。
编辑:
我只是想知道是否有一种方法可以使用正则表达式匹配三个词(比如 HTTP
、Response code
、503
),即使这些词没有出现在句子中的顺序相同。
有人可以建议使用 groovy 的正则表达式来匹配这个条件吗?
在Groovy中,你可以使用下面的检查(假设text
是保存你在问题中提供的字符串的变量):
if (text=~/Server returned HTTP response code: 503\b/){
println "503 code detected"
} else {
println "503 code not detected"
}
但你似乎也可以使用 contains
:
if (text.contains('HTTP response code: 503 ') {...}
我的回复如下。
<reply>
<status description="Error: REST call to http://localhost:8090/nmradapter/nmr/getICCIDDetails/123 failed: Server returned HTTP response code: 503 for URL: http://localhost:8090/nmradapter/nmr/getICCIDDetails/123 " />
</reply>
我已经使用 XML 解析器来解析响应,并且我需要通过响应检查状态描述是否包含响应代码 503。
编辑:
我只是想知道是否有一种方法可以使用正则表达式匹配三个词(比如 HTTP
、Response code
、503
),即使这些词没有出现在句子中的顺序相同。
有人可以建议使用 groovy 的正则表达式来匹配这个条件吗?
在Groovy中,你可以使用下面的检查(假设text
是保存你在问题中提供的字符串的变量):
if (text=~/Server returned HTTP response code: 503\b/){
println "503 code detected"
} else {
println "503 code not detected"
}
但你似乎也可以使用 contains
:
if (text.contains('HTTP response code: 503 ') {...}