简体   繁体   English

如何在QTP中使用XML中的XPATH中的正则表达式

[英]How to Use Regular Expression in XPATH in XML in QTP

I am facing a issue in QTP, i have to select a node value using regular expressions in XML 我在QTP中遇到问题,我必须使用XML中的正则表达式选择节点值

My Xml outputs the code as shown below 我的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>

Here if you observe the second line of the XML, we have MessageStatus but sometimes I get messageStatus . 在这里,如果您观察XML的第二行,我们有MessageStatus但有时我得到messageStatus

I want to handle this situation with a single XPath so that if lowercase tag or uppercase tag MessageStatus appears it should match and return the value. 我想用一个XPath来处理这种情况,这样如果出现小写标签或大写标签MessageStatus它应匹配并返回该值。

My code for Retrieving the value is as below 我的检索值的代码如下

Set ObjXml = Createobject("Microsoft.XMLDOM")

Case 1 情况1

Set ObjNode=ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/.*essageStatus")
ResultText=ObjNode.text

Case 2 案例2

Set ObjNode=ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/[m|M]essageStatus")
ResultText=ObjNode.text

Case 3 案例3

Set ObjNode=ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements//wsageStatus")
ResultText=ObjNode.text

But none of them worked, please help me. 但是他们都没有工作,请帮助我。

Is that always the first child element? 这总是第一个子元素吗? You can try 你可以试试

/soap:Envelope/soap:Body/*/MessageElements/*[1]

XPath doesn't support regular expressions in the way you're trying to use them (it doesn't support them at all in XPath 1.0), but you can do what you want with XPath不支持您尝试使用它们的正则表达式(它在XPath 1.0中根本不支持它们),但是你可以做你想要的

/soap:Envelope/soap:Body/*/MessageElements/*[self::MessageStatus | self::messageStatus]

assuming the namespace binding for the soap prefix is set up correctly (I'm not familiar with the particular technology you're using). 假设soap前缀的命名空间绑定已正确设置(我不熟悉您正在使用的特定技术)。 If the namespaces cause a problem then the easiest workaround would be to use just 如果命名空间导致问题,那么最简单的解决方法是使用just

//MessageElements/*[self::MessageStatus | self::messageStatus]

to find MessageElements wherever it occurs. 在任何地方查找MessageElements

Thanks a lot freinds for your inputs 非常感谢您的投入

Finally it has solved with the xpath /soap:Envelope/soap:Body/ /MessageElements/ [0] 最后它用xpath / soap解决了:Envelope / soap:Body / / MessageElements / [0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM