Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2009, 06:06 AM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Xpath Query Problem

I have the following XML File:

<?xml version="1.0" standalone="yes"?>
<ContactInformation>
<Country Name="Pakistan">
<City Name="Karachi">
<Region Name="North-Region">
<Route Number="1">
<Shop>Azeem Medical Store</Shop>
<Shop>Saeed Whole Sale Store</Shop>
<Shop>Azeem Super Store</Shop>
<Shop>Shahid Medical Store</Shop>
</Route>
<Route Number="2">
<Shop>Saeed Medical Store</Shop>
<Shop>Raheel Whole Sale Store</Shop>
</Route>
</Region>
</City>
</Country>
<Country Name="India">
<City Name="Delhi">
<Region Name="South-Region">
<Route Number="12">
<Shop>M. General Store</Shop>
</Route>
</Region>
</City>
</Country>
</ContactInformation>

What query should i use in xpath to retrieve all the nodes where Country Name='Pakistan'. I dont want to loop through the child nodes just to reach my required nodes by xpath query. Any help would be appreciated..Thanks
 
Old July 11th, 2009, 07:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

A great resource for learning XPath is the W3Schools web site: http://www.w3schools.com/Xpath/

To refer to the Name attribute you use @Name, and to perform a predicate (or filter) you put your criteria in square brackets [x=y], so /ContactInformation/Country[@Name='Pakistan'] would do what you want.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Xpath problem deean XSLT 10 June 18th, 2008 11:23 AM
xpath query blitzer XSLT 2 May 19th, 2007 03:54 AM
Read xpath query from node value jaquing XSLT 2 January 11th, 2006 06:50 PM
Binding Results of an Xpath query to a datagrid cowa ADO.NET 2 November 17th, 2003 02:40 AM
.NET XPath query not coming out right perropicante C# 0 June 15th, 2003 10:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.