对于特定元素中的属性,我将返回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>
答案 0 :(得分:0)
我认为问题是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
从而规避了命名空间问题。该测试步骤的结果应该易于传递。