为 soapUI 属性 传输的某些部分返回 Null

Getting Null returned for some portion of soapUI property transfer

我正在为特定元素中的属性返回 null。我尝试在 "NDCMSG_Payload" 标记中传输的任何属性或节点值都给出 null 。我可以在 NDCMSG_Header 标签中传输 属性。我希望有人能发现问题。

带有命名空间的属性传输代码是:

declare namespace soap="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace ns2="http://sita.aero/NDC/NDCUtility/v1";
declare namespace xmlns="http://www.iata.org/IATA/EDIST/2017.2";
/soap:Envelope/soap:Body/ns2:NDCMSG_Envelope/NDCMSG_Body/NDCMSG_Payload/OrderViewRS/Document

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:NDCMSG_Envelope xmlns:ns2="http://sita.aero/NDC/NDCUtility/v1">
         <NDCMSG_Header>              
            <MessageId>ID-1548230775813-0-48297-2</MessageId>
         </NDCMSG_Header>
         <NDCMSG_Body>
            <NDCMSG_Payload>
               <OrderViewRS PrimaryLangID="en" Target="Test" TimeStamp="2019-02-15T11:05:12.305+00:00" Version="16.23" xmlns="http://www.iata.org/IATA/EDIST/2017.2">
                  <Document id="PGU8NA">
                     <Name>Air Canada</Name>
                     <ReferenceVersion>UAT-OTA-2010B</ReferenceVersion>
                  </Document>
            </NDCMSG_Payload>
         </NDCMSG_Body>
      </ns2:NDCMSG_Envelope>
    </soap:Body>
</soap:Envelope>

我认为问题出在 OrderViewRS,它声明了一个通用命名空间:

xmlns="http://www.iata.org/IATA/EDIST/2017.2"

在您的 xpath 中声明了它,但您也有更高级别的元素,这些元素不在该命名空间中。当我给这个命名空间一个特定的名称,并将该命名空间添加到该级别和更深层次的标签时,xpath 会按预期工作。

declare namespace soap="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace ns2="http://sita.aero/NDC/NDCUtility/v1";
declare namespace ns3="http://www.iata.org/IATA/EDIST/2017.2";
/soap:Envelope/soap:Body/ns2:NDCMSG_Envelope/NDCMSG_Body/NDCMSG_Payload/ns3:OrderViewRS/ns3:Document/ns3:Name

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:NDCMSG_Envelope xmlns:ns2="http://sita.aero/NDC/NDCUtility/v1">
         <NDCMSG_Header>              
            <MessageId>ID-1548230775813-0-48297-2</MessageId>
         </NDCMSG_Header>
         <NDCMSG_Body>
            <NDCMSG_Payload>
               <ns3:OrderViewRS PrimaryLangID="en" Target="Test" TimeStamp="2019-02-15T11:05:12.305+00:00" Version="16.23" xmlns:ns3="http://www.iata.org/IATA/EDIST/2017.2">
                  <ns3:Document id="PGU8NA">
                     <ns3:Name>Air Canada</ns3:Name>
                     <ns3:ReferenceVersion>UAT-OTA-2010B</ns3:ReferenceVersion>
                  </ns3:Document>
               </ns3:OrderViewRS>
            </NDCMSG_Payload>
         </NDCMSG_Body>
      </ns2:NDCMSG_Envelope>
    </soap:Body>
</soap:Envelope>

您可能希望使用 XML Slurper 将 属性 传输作为 Groovy 脚本测试步骤。它可能是这样的:

def xml = context.expand( '${TestStepName#Response}' )
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder(xml)
def response = new XmlSlurper().parseText(holder.getXml())
def value = response.Body.NDCMSG_Envelope.NDCMSG_Body.NDCMSG_Payload.OrderViewRS.Document.Name
return value

从而规避命名空间问题。这个测试步骤的结果应该很容易转移。