473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XPath troubles

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
1 1173


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
0
by: Francesc Guim Bernat | last post by:
Dear colleagues, i'm getting in troubles using one XML library with Visual Studio .NET and Xerces with Xalan. (Xercer 2.4 and Xalan 1.7) When i execute the code i get the next run time error: ...
6
by: Stefan Franke | last post by:
Hi, I've got a little bit of a problem when dealing with namespaces and XPath. I'm trying very basic things, like showing all the nodes of one particular namespace. Here is my XPath statement:...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.