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 February 24th, 2006, 01:21 PM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XPath node selection

Hi all,
I want to select nodes from a given xml where the nodes have the same values for 2 out of 3 attributes usign XPath. For eg. The xml can have the format:

<root>
 <SearchFilter>
   <QueryParameters name="BID" value="531,532" by="3" />
   <QueryParameters name="LN" value="TEST,Que" by="2" />
   <QueryParameters name="GP" value="ERRR" by="3" />
   <QueryParameters name="BID" value="539" by="3" />
   <QueryParameters name="BID" value="537" by="2" />
 </SearchFilter>
</root>

The resultant XmlNodeList should have the node:
<QueryParameters name="BID" value="539" by="3" /> if I need to select name="BID" and by="3".

I used the following command:
XmlNodeList xn1 = srcXDoc.SelectNodes("//QueryParameters[(@name=preceding-sibling::QueryParameters/@name and @by= preceding-sibling::QueryParameters/@by)]");

But the resultant nodelist contains both the nodes:
   <QueryParameters name="BID" value="539" by="3" />
   <QueryParameters name="BID" value="537" by="2" />
It seems that the second attribute value is not being considered by the XPath. Please let me know the mistake I am committing.

 
Old March 4th, 2006, 09:40 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

XmlNodeList xn1 = srcXDoc.SelectNodes("//QueryParameters[(@name=preceding-sibling::QueryParameters/@name and @by= preceding-sibling::QueryParameters/@by)]");

The problem is your xpath. What you're currently looking for is a node that has a name attribute matching a previous one, and a by attribute matching a previous one (not necessarily the same)

What you said you want is 'name="BID" and by="3".'
XmlNodeList xn1 = srcXDoc.SelectNodes("//QueryParameters[(@name='BID' and @by='3')]");






Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath to get next node (sibling) jeft0nes XSLT 2 August 8th, 2007 08:30 PM
XML: How to select a node with ' in it using Xpath guozai BOOK: Professional C#, 2nd and 3rd Editions 1 October 6th, 2006 12:37 PM
Read xpath query from node value jaquing XSLT 2 January 11th, 2006 06:50 PM
Access Namespace Node using XPath pvasudevan XSLT 1 January 2nd, 2006 06:20 AM
xpath: position parent of current node orion83 XSLT 1 September 5th, 2005 07:20 AM





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