質問

I am using soapui for automation testing. I am trying to write a xpath expression to do the property transfer with following xml

<snapshots query="after=2014-04-16 12:30:00-0700" mask="op" xmlns="http://ws.example.com/roma/201907" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <AsOf>2014-04-16T19:20:44-07:00</AsOf>
    <offers>
        <offer entityId="6500588"/>
        <offer entityId="6500589"/>
        <offer entityId="6500590"/>
        <offer entityId="6557335">
            <rubber>KJM</rubber>
            <code>B44733</code>
            <offerCode>PA</offerCode>
            <status name="Completed">C</status>
            <startDate basis="GMT-4">2013-04-01</startDate>
            <endDate basis="GMT-4">2014-04-15</endDate>
            <template>
                <sourceKey-Ref entityId="36KTV" code="KPA513C36KTV" uri="/snapshot/sourcekey/36KTV"/>
                <pTemplateCode>PPAKXC</pTemplateCode>
                <panelCode>HPA5LTM</panelCode>
                <itemCode>PA1467</itemCode>
            </template>
            <venue code="28">
                <supervenue>5</supervenue>
            </venue>
            <currencyDetail currency="USD">
                <unitPrice>29.95</unitPrice>
                <numberPayments>1</numberPayments>
            </currencyDetail>
            <hData>
                <legacyScriptCode>300</legacyScriptCode>
                <hpKeycode>189161</hpKeycode>
                <hpProductNumber>014399</hpProductNumber>
                <hpMpgCode>300</hpMpgCode>
            </hData>
        </offer>
        <offer entityId="6557336">
            <rubber>KJM</rubber>
            <code>B44734</code>
            <offerCode>VY</offerCode>
            <status name="Completed">C</status>
            <startDate basis="GMT-4">2013-04-01</startDate>
            <endDate basis="GMT-4">2014-04-15</endDate>
            <template>
                <sourceKey-Ref entityId="36KTV" code="KPA513C36KTV" uri="/snapshot/sourcekey/36KTV"/>
                <pTemplateCode>PPAKXC</pTemplateCode>
                <panelCode>HPA5LTM</panelCode>
                <offerCode>OVYC8UM9</offerCode>
                <itemCode>VY4023</itemCode>
            </template>
            <venue code="28">
                <supervenue>5</supervenue>
            </venue>
            <currencyDetail currency="USD">
                <unitPrice>0.00</unitPrice>
                <numberPayments>1</numberPayments>
            </currencyDetail>
            <hData>
                <legacyScriptCode>947</legacyScriptCode>
                <hpKeycode>189162</hpKeycode>
                <hpProductNumber>602185</hpProductNumber>
                <hpMpgCode>947</hpMpgCode>
            </hData>
        </offer>
        <offer entityId="6557337">
            <rubber>KJM</rubber>
            <code>B44736</code>
            <offerCode>VY</offerCode>
            <status name="Completed">C</status>
            <startDate basis="GMT-4">2013-04-01</startDate>
            <endDate basis="GMT-4">2014-04-15</endDate>
            <template>
                <sourceKey-Ref entityId="36KTV" code="KPA513C36KTV" uri="/snapshot/sourcekey/36KTV"/>
                <pTemplateCode>PPAKXC</pTemplateCode>
                <panelCode>HPA5LTM</panelCode>
                <offerCode>OVYC8UMA</offerCode>
                <itemCode>VY4012</itemCode>
            </template>
            <venue code="28">
                <supervenue>5</supervenue>
            </venue>
            <currencyDetail currency="USD">
                <unitPrice>0.00</unitPrice>
                <numberPayments>1</numberPayments>
                <firstPaymentAmount>0.00</firstPaymentAmount>
                <firstShippingAmount>5.98</firstShippingAmount>
            </currencyDetail>
            <hData>
                <legacyScriptCode>947</legacyScriptCode>
                <hpKeycode>189163</hpKeycode>
                <hpProductNumber>602094</hpProductNumber>
                <hpMpgCode>947</hpMpgCode>
            </hData>
        </offer>
    </offers>
</snapshots>

I would like to have all hpKeycode using local-name() in the XPath expression. I tried

//*[local-name()='hpKeycode']

but this gives me only the first node which is 189161. This

/*[local-name()='hpKeycode'][2]

also does not work. Any help would be greatly appreciated.

役に立ちましたか?

解決

You can try with XQuery. In the property transfer step select Use XQuery checkbox as you see in the image below. And use this code:

declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://ws.example.com/roma/201907';
<ns1:offer>
{
  for $id in //*[local-name()='hpKeycode'] return string($id)
}
</ns1:offer>

SOAPUI property transfer XQuery

EDIT:

If you want to avoid the use of XQuery, you can add three Transfers on your property transfer, on each one use:

First id (//*[local-name()='hpKeycode'])[1]

Second id (//*[local-name()='hpKeycode'])[2]

Third id (//*[local-name()='hpKeycode'])[3]

SOAPUI property transfer XPath

Hope this helps,

他のヒント

This would not work in the way you expect it to because you are pulling a single set of values. You would need to specify what node branch you want further up the tree.

Its like road ways... if you were giving someone directions you would need to inform them which way to go for each fork in the road. Lets say you wanted to tell them how to get to one of 3 possible airports each located in a different city. If you said "as you arrive at airports 1,2, and 3 enter the 2nd". They would be baffled and say something like "what city though?" and maybe "its not possible for them to exist in the same location".

Solution:

Here is what you would want given the xml you provided (both work in soapui).

Xpath 2.0

//*:offer[4]/*:hData/*:hpKeycode
//*:offer[5]/*:hData/*:hpKeycode
//*:offer[6]/*:hData/*:hpKeycode

Xpath 1.0

//*[local-name()='offer'][4]/*[local-name()='hData']/*[local-name()='hpKeycode']
//*[local-name()='offer'][5]/*[local-name()='hData']/*[local-name()='hpKeycode']
//*[local-name()='offer'][6]/*[local-name()='hData']/*[local-name()='hpKeycode']

Hope this more detailed explanation helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top