XPath troubles

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi

Only think I am sure of is that I am doing something wrong :-)

Never worked on a xml format like this but what I am trying to do is loop
thru

L1 get all the possible Companies

The go to L2 and for each company get all the Division

Then go to L3 and get all Cars within the Division

I have a couple questions

1)What would be the best way to do this?? with the possibility that there
may someday be L4,L5

2) Couple problems I cannot explain below my xPath code



Thanks



XmlDataDocument doc = new XmlDataDocument();

doc.Load("s4.xml");

XPathNavigator nav3 = doc.CreateNavigator();

XPathNodeIterator iterator2 = nav3.Select("/NewDataSet/l2");
///This seems to work

XPathNodeIterator iterator2 =
nav3.Select("/NewDataSet/l3[Division=Pontiac]"); ///This doesn't work -
Why???



<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<l1>
<ID>Total</ID>
<Company>GM</Company>
<Sum_x0020_of_x0020_HoursDev>43310</Sum_x0020_of_x0020_HoursDev>
<Sum_x0020_of_x0020_MarketLife>9880</Sum_x0020_of_x0020_MarketLife>
</l1>
<l2>
<ID>Total</ID>
<Company>GM</Company>
<Division>Pontiac</Division>
<Sum_x0020_of_x0020_HoursDev>1130</Sum_x0020_of_x0020_HoursDev>
<Sum_x0020_of_x0020_MarketLife>630</Sum_x0020_of_x0020_MarketLife>
</l2>
<l2>
<ID>Total</ID>
<Company>GM</Company>
<Division>Buick</Division>
<Sum_x0020_of_x0020_HoursDev>294</Sum_x0020_of_x0020_HoursDev>
<Sum_x0020_of_x0020_MarketLife>84</Sum_x0020_of_x0020_MarketLife>
</l2>
<l2>
<ID>Total</ID>
<Company>GM</Company>
<Division>Cadillac</Division>
<Sum_x0020_of_x0020_HoursDev>5658</Sum_x0020_of_x0020_HoursDev>
<Sum_x0020_of_x0020_MarketLife>2038</Sum_x0020_of_x0020_MarketLife>
</l2>
<l3>
<ID>Total</ID>
<Company>GM</Company>
<Division>Pontiac</Division>
<Car>GTO</Car>
<Sum_x0020_of_x0020_HoursDev>82</Sum_x0020_of_x0020_HoursDev>
<Sum_x0020_of_x0020_MarketLife>4</Sum_x0020_of_x0020_MarketLife>
</l3>
<l3>
<ID>Total</ID>
<Company>GM</Company>
<Division>Pontiac</Division>
<Car>Grand Prix</Car>
<Sum_x0020_of_x0020_HoursDev>134</Sum_x0020_of_x0020_HoursDev>
<Sum_x0020_of_x0020_MarketLife>38</Sum_x0020_of_x0020_MarketLife>
</l3>
</NewDataSet>
 
Joe wrote:

XPathNodeIterator iterator2 =
nav3.Select("/NewDataSet/l3[Division=Pontiac]"); ///This doesn't work -
Why???

You need to quote the string literal you want to compare to e.g.
nav3.Select("/NewDataSet/l3[Division = 'Pontiac']")
 
Back
Top