문제

I am facing a issue in QTP, i have to select a node value using regular expressions in XML

My Xml outputs the code as shown below

 <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.

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.

My code for Retrieving the value is as below

Set ObjXml = Createobject("Microsoft.XMLDOM")

Case 1

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

Case 2

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

Case 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

/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). If the namespaces cause a problem then the easiest workaround would be to use just

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

to find MessageElements wherever it occurs.

Thanks a lot freinds for your inputs

Finally it has solved with the xpath /soap:Envelope/soap:Body//MessageElements/[0]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top