0

This is my sample XML File:

<Cars>
     <Make name="Maruthi">
         <Model>
             <Name>Wagnor</Name>
             <Release>2000</Release>
         </Model>
     </Make>
     <Make name="Maruthi">
         <Model>
              <Name>Swift</Name>
              <Release>2005</Release>
         </Model>
     </Make>
     <Make name="Hundai">
         <Model>
             <Name>i10</Name>
             <Release>2003</Release>
         </Model>
     </Make>
</Cars>

I want to retrieve all cars where Make Name is=Maruthi(so here i am expecting two Cars out of three)

Set o_XML=XMLUtil.CreateXMLFromFile("E:\Programming Samples\QTP Samples\Cars.xml")
set o_ChildPath=o_XML.ChildElementsByPath("/Cars/Make/[name='Maruthi']")

'Here XMLUtil is utility object provided by QTP, but i dont see any problem there.

The only problem is in evaluating the expression. I tried different expressions but i am getting "expression must evalute to a node-set".

Can someone help in here?

Andrei Sfat
  • 8,440
  • 5
  • 49
  • 69
Uday
  • 1,433
  • 10
  • 36
  • 57

3 Answers3

1

Why don't you use JAXB parser. It would get a list of car objects for you and then you can retrieve all car of "Maruthi" make.

dareurdream
  • 241
  • 4
  • 13
1

It looks as if you're trying to pass an XPath expression to ChildElementsByPath. If it accepts XPath (sorry, I don't use the tool and can't find documentation on the Web), you want the expression to be /Cars/Make[name='Maruthi'] (drop the last slash). If it doesn't accept XPath, you may want to use /Cars/Make and use your own code to filter out the unwanted makes.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
0

Maybe you need an XML header? You can read here about this:

Is a valid XML file required xml header declaration

Community
  • 1
  • 1