HighTechTalks DotNet Forums  

Xpath For All Values

Dotnet XML microsoft.public.dotnet.xml


Discuss Xpath For All Values in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Derek Hart
 
Posts: n/a

Default Xpath For All Values - 12-13-2007 , 05:13 PM






Trying to figure out how to do an xpath that has all values equal to 0.

//Record/AccidentIncome[.=0]

I know this will find ANY instance where AccidentIncome = 0, but I need to
determine if ALL nodes that have //Record/AccidentIncome equal to 0. Stated
another way, I cannot figure out how to do the opposite - determine if any
node has a value greater than zero, which is easy
//Record/AccidentIncome[.>0] - but then use a keyword like not to reverse it
and get a true statement.

So if I have 2 nodes, and one of them has AccidentIncome = 5000, I wish this
statement would become true, but it does not.

not //Record/AccidentIncome[.>0]

Please help.



Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Xpath For All Values - 12-14-2007 , 06:39 AM






Derek Hart wrote:
Quote:
Trying to figure out how to do an xpath that has all values equal to 0.

//Record/AccidentIncome[.=0]

I know this will find ANY instance where AccidentIncome = 0, but I need to
determine if ALL nodes that have //Record/AccidentIncome equal to 0. Stated
another way, I cannot figure out how to do the opposite - determine if any
node has a value greater than zero, which is easy
//Record/AccidentIncome[.>0] - but then use a keyword like not to reverse it
and get a true statement.

So if I have 2 nodes, and one of them has AccidentIncome = 5000, I wish this
statement would become true, but it does not.

not //Record/AccidentIncome[.>0]
I am not sure I understand what you are trying to achieve. If you have
one element <AccidentIncome>5000</AccidentIncome> then the XPath expression
//Record/AccidentIncome[. > 0]
selects that element and the node-set selected contains that one node.
Thus if you want to determine whether at least one such element exists
then you can count the elements in the node-set either by checking e.g.
xmlDocument.SelectNodes("//Record/AccidentIncome[. > 0]").Count > 0
or by evaluating the XPath expression
count(//Record/AccidentIncome[. > 0]) > 0
You can also convert a node-set to a boolean and only an emtpy node-set
converts to false, otherwise you get true e.g.
boolean(//Record/AccidentIncome[. > 0])
gives true if there is at least one element in the node-set.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.