开发者

SoapUI property transfer and xpath/xquery number formatting

I have this property-transfer in SoapUI:

declare namespace soapEnv="http://schemas.xmlsoap.org/soap/envelope/";
//soapEnv:Body/LoginResponse/baseSequenceId

and lets say it returns 123456. But I want 123457 (what I get +1)

I tried this:

declare namespace soapEnv="http://schemas.xmlsoap.org/soap/envelope/";
//soapEnv:Body/LoginResponse/baseSequenceId + 1

but I get 123457.0 as a result. I tried some reformatting methods I found, but most possibly I did not use them in the correct way. I am quite new at this stuff.

I also tried this (wi开发者_运维知识库th xquery):

declare namespace soapEnv="http://schemas.xmlsoap.org/soap/envelope/";
let $x := //soapEnv:Body/LoginResponse/baseSequenceId
return $x

and tried several things with $x but everything I tried ended up with null or InvocationTargetException.

Any help is appreciated !


Thanks a lot for your suggestions, although I couldn't make them work :(
Maybe there is something wrong with my SoapUI because all xpath functions return null..

I made it work with groovy:

groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

loginResponse = groovyUtils.getXmlHolder("Login#Response")
loginResponse.declareNamespace( "soapEnv", "http://schemas.xmlsoap.org/soap/envelope/" )
sessionIdStr = loginResponse.getNodeValue( "//soapEnv:Body/LoginResponse/sessionId" )
baseSequenceIdStr = loginResponse.getNodeValue( "//soapEnv:Body/LoginResponse/baseSequenceId" )
sequenceIdStr = (baseSequenceIdStr.toInteger() + 1).toString()

createRequest = groovyUtils.getXmlHolder("Create#Request")
createRequest.declareNamespace( "soapEnv", "http://schemas.xmlsoap.org/soap/envelope/" )
createRequest.setNodeValue( "//soapEnv:Header/SessionId", sessionIdStr )
createRequest.setNodeValue( "//soapEnv:Header/TransactionId", baseSequenceIdStr )
createRequest.setNodeValue( "//soapEnv:Header/SequenceId", sequenceIdStr )
createRequest.updateProperty()


Note that if the value of //soapEnv:Body/LoginResponse/baseSequenceId + 1 is an integer, XPath should not put in a decimal point when converting it to a string.

But maybe in this case XPath is returning a number, and it's SoapUI that's converting it to a string, and using a decimal point.

I would first try (updated):

string(//soapEnv:Body/LoginResponse/baseSequenceId + 1)

This is to force the conversion to string to happen within XPath, so that SoapUI won't have a chance to do anything funny with a numeric value.

Alternatively, you could try

floor(//soapEnv:Body/LoginResponse/baseSequenceId + 1)

or even

string(floor(...))

If that doesn't work, you could try

substring-before(//soapEnv:Body/LoginResponse/baseSequenceId + 1, '.')

It's not very elegant, but it might work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜