我为特定元素中的属性返回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
从而绕过命名空间问题。这个测试步骤的结果应该很容易转移。