473,472 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with xpath query

Hi!

Here's a XML reprensenting a company. I would like to make a XPath
query that gives me all the employees that are Programmer or Analyst
and have 5 years of experience.

I did the following query
"//*[local-name()='Employee']/*[(local-name()='Position' and
(text()='Programmer' or
text()='Analyst'))]//parent::*/*[(local-name()='YearsOfExperience' and
text()='5')]//parent::*" and it gives me 4 nodes. The 2 I need and one
for Position and another for YearsOfExperience.

Please help me to get through this!

I'm using VB.net and I cannot change the xml structure. I would like to
return it as an XML document.

Here's my XML file:

<Company xmlns="http://www.mynamespace.com/MyCompany">
<Id>1</Id><Name>MyCompany Name</Name>
<ListOfEmployees>
<Employee>
<Number>65239</Number>
<Position>Programmer</Position>
<Name>Johnny</Name>
<Firstname>McDonald</Firstname>
<YearsOfExperience>5</YearsOfExperience>
</Employee>
<Employee>
<Number>18544</Number>
<Position>Boss</Position>
<Name>The Kid</Name>
<Firstname>Billy</Firstname>
<YearsOfExperience>21</YearsOfExperience>
</Employee>
<Employee>
<Number>23463</Number>
<Position>Analyst</Position>
<Name>King</Name>
<Firstname>Kerry</Firstname>
<YearsOfExperience>5</YearsOfExperience>
</Employee>
</ListOfEmployees>
</Company>

Thanks!

Jeff

Nov 12 '05 #1
1 1125

je******@globetrotter.net wrote:
*Hi!

Here's a XML reprensenting a company. I would like to make a XPath
query that gives me all the employees that are Programmer or Analyst
and have 5 years of experience.

I did the following query
"//*[local-name()='Employee']/*[(local-name()='Position' and
(text()='Programmer' or
text()='Analyst'))]//parent::*/*[(local-name()='YearsOfExperience'
and
text()='5')]//parent::*" and it gives me 4 nodes. The 2 I need and
one
for Position and another for YearsOfExperience.

Please help me to get through this!

I'm using VB.net and I cannot change the xml structure. I would like
to
return it as an XML document.

Thanks!

Jeff *


Hi Jeff,

To find any employee node with programmer OR an analyst with 5 years of
experience:
"//Employee[ descendant::Position[text()='Programmer' or
(text()='Analyst' and parent::Employee/YearsOfExperience[text()='5'])]
]"

You can modify this by changing the brackets to find programmers and
analysts that each have 5 years of experience:
"//Employee[ descendant::Position[ ( text()='Programmer' or
text()='Analyst' ) and (
parent::Employee/YearsOfExperience[text()='5'] )] ]"

Hope that helps,
Dan

--
danprime
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message1861950.html

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Hi all, I have recently started working with the new XML functionality in PHP5, but I am running into a few problems. Specifically, I am using an Xpath query to try and pull out the data in...
8
by: Terry P | last post by:
Are there any tools (java classes, tag libraries) which can translate xpath statements into a SQL query? Given an xpath query which has a predicate that filters node values or attributes, I want...
3
by: gfrommer | last post by:
Hello Everyone, I'm writing a server in java, and I want the clients to pass me an XPath query. I want the XPath queries to be in a specific format though, I'm pretty sure it's valid but I want...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
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>
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
2
by: Riki | last post by:
I'm stuck with an XPath query to produce a TreeView. From the data below, I want to select all the score elements having an IdIn of 2018, ***including their ancestors***. With the result, I want...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to construct an XPath query against an XML document, for a requirement that I have. Below is the XML fragment: <SUBMISSIONS> <SUBMISSION YEAR="2004"> <MONTH...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.