Forum Discussion

pkinoc's avatar
pkinoc
Occasional Contributor
12 years ago

context.expand bug???

I pasted two snippets of XML below.

One contains <COUNTY>Orange</COUNTY>

The other contains <COUNTY/>

The context.expand statement below returns Orange for the first snippet but <COUNTY/> for the second. Shouldn't it return either null or an empty string or am I doing something wrong?

The context.expand statement was generated with the Get Data feature.


def Property_county = context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; //body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1]}' )



Fri Apr 20 16:10:01 PDT 2012:INFO:MSGLOG_Property: <PROPERTY><SEQ_NUM>1</SEQ_NUM><LINE1>8256 FERNGLEN DR </LINE1><CITY>Portland</CITY><STATE>OR</STATE><ZIP>97200</ZIP><COUNTY>Orange</COUNTY><PROPERTYTYPE>112</PROPERTYTYPE><SALESAMOUNT>580000.00</SALESAMOUNT><SITUS>
<NUMBER>93912</NUMBER>
<NAME>RIO</NAME>
<STREETTYPE>ST</STREETTYPE>
</SITUS></PROPERTY>


Fri Apr 20 16:37:52 PDT 2012:INFO:MSGLOG_Property: <PROPERTY><SEQ_NUM>1</SEQ_NUM><LINE1>5 Company Street</LINE1><CITY>St. Croix </CITY><STATE>VI</STATE><ZIP>00820</ZIP><COUNTY/><PROPERTYTYPE>112</PROPERTYTYPE><SALESAMOUNT>580000.00</SALESAMOUNT><SITUS>
<NUMBER>93912</NUMBER>
<NAME>RIO</NAME>
<STREETTYPE>ST</STREETTYPE>
</SITUS></PROPERTY>

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    This is actually how XPath works, and is the expected behavior. A little counter-intuitive I agree, but correct nontheless. Anyway, I'm certainly no XPath expert, so this might be a convoluted way of getting the information you're after, but at least it works:


    content = null
    if( context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; exists(//body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1])}' ) == 'true' ) {
    //Element exists!
    if( context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; string-length(//body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1]) = 0}' ) ) {
    //Element is empty!
    content = ""
    } else {
    //Element has content!
    content = context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; //body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1]}' )
    }
    }

    log.info content


    Regards,
    Dain
    SmartBear Software
  • pkinoc's avatar
    pkinoc
    Occasional Contributor
    So how do you put something like that in an XPath Match?

    If it's not a plain vanilla example do you not have any choice but to write a groovy script and include what u wrote?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi again!

    Maybe you could put it into a Script Assertion like this:

    content = null
    if( context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; exists(//body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1])}' ) == 'true' ) {
    //Element exists!
    if( context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; string-length(//body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1]) = 0}' ) ) {
    //Element is empty!
    content = ""
    } else {
    //Element has content!
    content = context.expand( '${DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE#declare namespace re_1=\'urn://esb.fnf.com/ESBOrderGateway/NextAceTranslatorResult\'; //body[1]/re_1:receive[1]/result[1]/PROPERTY[1]/COUNTY[1]}' )
    }
    }

    assert content != null


    or you could put it into an Assertion TestStep

    Does that make sense?

    --
    Regards

    Erik
    SmartBear Sweden
  • def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );

    def getData = groovyUtils.getXmlHolder('DataSource - Get MessageLog XML - NextAceRequestMessageLogger#MSGLOG_MESSAGE')

    getDataResp.getNodeValue('*:receive[1]/result[1]/PROPERTY[1]/COUNTY[1]')