473,397 Members | 2,077 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,397 software developers and data experts.

XPath beginners question

I have limited experience of XML and I am trying to use XPath to get at
all <tag4> elements given a certain value for <tag3> (see my example
below :

<?xml version="1.0" encoding="ISO-8859-1"?>
<tag1>
<tag2>
<tag3>
<tag4>
<tag4>
<tag4>
</tag2>
<tag2>
<tag3>
<tag4>
<tag4>
</tag2>
</tag1>

Any assistance would be really appreciated.
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
2 1050


Mike P wrote:
I have limited experience of XML and I am trying to use XPath to get at
all <tag4> elements given a certain value for <tag3> (see my example
below :

<?xml version="1.0" encoding="ISO-8859-1"?>
<tag1>
<tag2>
<tag3>
<tag4>
<tag4>
<tag4>
</tag2>
<tag2>
<tag3>
<tag4>
<tag4>
</tag2>
</tag1>


You are missing a lot of closing tags above, also <tag3> elements do no
even have a content so it is not clear what you want to regard as the
value of <tag3>.

Assuming you had the following XML

<?xml version="1.0" encoding="UTF-8"?>
<tag1>
<tag2>
<tag3>Kibology</tag3>
<tag4 />
<tag4 />
<tag4 />
</tag2>
<tag2>
<tag3>whatever</tag3>
<tag4 />
<tag4 />
</tag2>
<tag2>
<tag3>Kibology</tag3>
<tag4 />
<tag4 />
</tag2>
</tag1>

and wanted to look for all <tag4> elements that have a preceding sibling
<tag3> element with the content (value) Kibology you could use the
following XPath expression:

/tag1/tag2/tag4[preceding-sibling::tag3 = 'Kibology']
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Hi Mike,

Try...

/tag1/tag2[tag3 = 'foo']/tag4

HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have limited experience of XML and I am trying to use XPath to get at
all <tag4> elements given a certain value for <tag3> (see my example
below :

<?xml version="1.0" encoding="ISO-8859-1"?>
<tag1>
<tag2>
<tag3>
<tag4>
<tag4>
<tag4>
</tag2>
<tag2>
<tag3>
<tag4>
<tag4>
</tag2>
</tag1>

Any assistance would be really appreciated.
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #3

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

Similar topics

3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
1
by: Andreas Håkansson | last post by:
Hello, Does anyone have any advice on a good XPath book? Perhaps two books, one at a beginners/intermediate level and one advanced. While on the subject I wouldn't mind some advice on the same...
2
by: trond | last post by:
Hello all, I am building a personal web site in VS2005 as a kind of learing project for myself, so forgive me if this is a novice question. I am planning to use an XML file called...
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>
8
by: sehiser | last post by:
Hello, I've been reading up on xpath and I am able to access elements with it. I haven't been able to figure one thing out though. How would I use XPath to select an element where the text...
7
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple...
0
by: pompair | last post by:
Hello, I'm making a quiz game for fun. I have an xml file like this: <?xml version="1.0" encoding="utf-8" ?> <results> <index>99</index> <answers>11</answers> <questions> <question id="1">
0
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...

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.