0

how can we check that the xpath in xml does not exist :

I have to perform text file to xml data comparison , XML file contains several transactions. some transactions contains tag while some does not. since i have understanding of these tags, i have captured the xpaths.

there is a situation when data exists in text file but corresponding tag in xml transaction is missing.

in report i am printing data values in both file. i want to print blank in case xpath does not exist or tag not present in a transaction. ?? how to handle it.

for Missing tag UFT throwing error : Failed to retrieve the item. The index is out of range.

     <Transaction>
                <xyz>alpha-4141</xyz>
                <abc>500005000002300</abc>
                <pqr>testing4141</pqr>
                <lmn>ED</lmn>
    </Transaction>
    <Transaction>
                <xyz>alpha-4142</xyz>
                <abc>900005000002400</abc>
                <lmn>ED</lmn>
    </Transaction>

text file data :

Trans_start alpha-4141 500005000002300 testing4141 ED Trans_end

Trans_start alpha-4142 900005000002400 testing4141 ED Trans_end

code : Set xmlObj = XMLUtil.CreateXML() xmlObj.LoadFile("E:\QTP-UFT\testing.xml") Set xyz=xmlObj.ChildElementsByPath("//Transaction//xyz")

To get value :

xmlvalueviaXpath=xpath.Item(index).Value()
2
  • 1
    That looks more like VB6 than VB.NET to me. Is it VB6? Or maybe VBA? Dec 26, 2018 at 17:48
  • You can use On Error Resume Next and On Error Goto 0 to handle and process the error gracefully. Jan 14, 2019 at 5:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.