473,387 Members | 1,540 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,387 software developers and data experts.

XPath



Consider the following XML

<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Data>
<ID>1005</ID>
<Reference>
<Reference>ABC</Reference>
<Country>UK</Country>
</Reference>
<Reference>
<Reference>123</Reference>
<Country>USA</Country>
</Reference>
</Data>
</Root>
Using XPath, I would like to: Select the value of the Reference Node,
Where the ID = 1005, And the Country is USA. The value of the node
would therefore be 123.

I'm not great with XPath, but had a go and got it completely wrong:
XPath = "//Data/[ID ="1005"]/../Reference/[Country="USA"]/Reference"

I'd be ever so grateful if someone can help out with this XPath!

Cheers
Simon
(If its any help, I'm using vs.net 2005 and trying to populate an
XPathNodeIterator using XPathNavigator.Select)

Dec 11 '07 #1
2 1315
SiJP wrote:
>
Consider the following XML

<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Data>
<ID>1005</ID>
<Reference>
<Reference>ABC</Reference>
<Country>UK</Country>
</Reference>
<Reference>
<Reference>123</Reference>
<Country>USA</Country>
</Reference>
</Data>
</Root>
Using XPath, I would like to: Select the value of the Reference Node,
Where the ID = 1005, And the Country is USA. The value of the node
would therefore be 123.
/Root/Data[ID = '1005']/Reference[Country = 'USA']/Reference

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 11 '07 #2
On 11 Dec, 12:28, Martin Honnen <mahotr...@yahoo.dewrote:
SiJP wrote:
Consider the following XML
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Data>
<ID>1005</ID>
<Reference>
<Reference>ABC</Reference>
<Country>UK</Country>
</Reference>
<Reference>
<Reference>123</Reference>
<Country>USA</Country>
</Reference>
</Data>
</Root>
Using XPath, I would like to: Select the value of the Reference Node,
Where the ID = 1005, And the Country is USA. The value of the node
would therefore be 123.

/Root/Data[ID = '1005']/Reference[Country = 'USA']/Reference

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thanks Martin - all sorted now!
Dec 13 '07 #3

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
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>
3
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0"...
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...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.