By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,465 Members | 1,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,465 IT Pros & Developers. It's quick & easy.

XPath troubles

P: n/a
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>
Apr 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a


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']")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.