如何使用 groovy 查找 xml 标签
how to find an xml tag using groovy
我想执行一个基本的 if 语句,如果 xml 标签 b:HotelId
没有显示,那么 log.info 为真,否则 log.info 为假,但是我不断得到真实显示。
<xxxxmlns:s="http://www.w3.org/xxx" xmlns:a="http://xxxg">
<xxxxx>
<xxx"></xxx>
</xxxxx>
<aaa>
<abc xmlns="...">
<bbb xmlns:b="..." xmlns:i="...">
</bbb>
<abc>
<aaa>
<b:HotelId>00000</b:HotelId>
如何更正 if 语句,以便在未显示标签时输出 true?
下面是我的 if 语句:
if (xml.'**'.any { it.name() != 'b:HotelId' })
{
log.info true
}
else
{
log.info false
}
给你,关注在线评论。
//Find if there is such element, HotelId, in the xml
def hotelId = xml.'**'.find{ it.name() == 'HotelId' }
//The size should be at least 1, so you want to print false
if (hotelId.size()) {
log.info 'element found'
log.info false
} else {
//you want to print true
log.info 'element not found'
log.info true
}
我想执行一个基本的 if 语句,如果 xml 标签 b:HotelId
没有显示,那么 log.info 为真,否则 log.info 为假,但是我不断得到真实显示。
<xxxxmlns:s="http://www.w3.org/xxx" xmlns:a="http://xxxg">
<xxxxx>
<xxx"></xxx>
</xxxxx>
<aaa>
<abc xmlns="...">
<bbb xmlns:b="..." xmlns:i="...">
</bbb>
<abc>
<aaa>
<b:HotelId>00000</b:HotelId>
如何更正 if 语句,以便在未显示标签时输出 true?
下面是我的 if 语句:
if (xml.'**'.any { it.name() != 'b:HotelId' })
{
log.info true
}
else
{
log.info false
}
给你,关注在线评论。
//Find if there is such element, HotelId, in the xml
def hotelId = xml.'**'.find{ it.name() == 'HotelId' }
//The size should be at least 1, so you want to print false
if (hotelId.size()) {
log.info 'element found'
log.info false
} else {
//you want to print true
log.info 'element not found'
log.info true
}