【发布时间】:2014-06-22 18:29:36
【问题描述】:
我在 QTP 中遇到问题,我必须使用 XML 中的正则表达式选择一个节点值
我的Xml输出代码如下图
<MessageElements xmlns="">
<MessageStatus>FAIL</MessageStatus>
<ErrorList>
<ErrorCode>1951</ErrorCode>
<ErrorMessage>No Data Found</ErrorMessage>
<ErrorStatus>F</ErrorStatus>
<ErrorText>OSSDataNotFoundError</ErrorText>
</ErrorList>
<MessageAddressing>
<from>ICL</from>
<to>ICL SOAPTester</to>
<relatesTo/>
<messageId>12345</messageId>
<action>SearchResource</action>
<timestamp>2008-09-29T07:19:45</timestamp>
<transactionId>1234</transactionId>
<ServiceName>SearchResource</ServiceName>
<ServiceVersion>2.0</ServiceVersion>
</MessageAddressing>
</MessageElements>
如果您观察 XML 的第二行,我们有 MessageStatus,但有时我会得到 messageStatus。
我想用单个 XPath 处理这种情况,这样如果出现小写标记或大写标记MessageStatus,它应该匹配并返回值。
我的检索值代码如下
Set ObjXml = Createobject("Microsoft.XMLDOM")
案例 1
Set ObjNode=ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/.*essageStatus")
ResultText=ObjNode.text
案例 2
Set ObjNode=ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/[m|M]essageStatus")
ResultText=ObjNode.text
案例 3
Set ObjNode=ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements//wsageStatus")
ResultText=ObjNode.text
但它们都不起作用,请帮助我。
【问题讨论】:
-
如果您正在测试生成此 XML 的服务,这种不可预测的大写不应该被视为错误吗?
-
旧要求与消息状态有关
-
新要求mrnts 与 MessageStatus 一起
标签: xml web-services soap xpath qtp