![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if the node does not exist but that is also the result for an empty node. |
#3
| |||
| |||
|
|
If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if the node does not exist but that is also the result for an empty node. |
#4
| |||
| |||
|
|
* David Thielen wrote in microsoft.public.dotnet.xml: If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if the node does not exist but that is also the result for an empty node. I do not know how you use the XPathNavigator, but using methods that return strings is not the right approach; also note that if your XPath expression evaluates to a string, there is no way to determine whether some nodes relevant for the expression exist or not. A simple method is to use nav.Evaluate("boolean(...)") and cast the result to a boolean. -- Björn Höhrmann · mailto:bjoern (AT) hoehrmann (DOT) de · http://bjoern.hoehrmann.de Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ |
#5
| |||
| |||
|
|
* David Thielen wrote in microsoft.public.dotnet.xml: If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if the node does not exist but that is also the result for an empty node. I do not know how you use the XPathNavigator, but using methods that return strings is not the right approach; also note that if your XPath expression evaluates to a string, there is no way to determine whether some nodes relevant for the expression exist or not. A simple method is to use nav.Evaluate("boolean(...)") and cast the result to a boolean. -- Björn Höhrmann · mailto:bjoern (AT) hoehrmann (DOT) de · http://bjoern.hoehrmann.de Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ |
#6
| |||
| |||
|
|
The problem with that is a user can feed us anything for the xpath - including true(). What we really need is something that returns any of the following: 1) not a legit xpath statement 2) xpath to a node - node exists 3) xpath to a node - node does not exist 4) other - like name(/root/node) |
#7
| |||
| |||
|
|
The problem with that is a user can feed us anything for the xpath - including true(). What we really need is something that returns any of the following: 1) not a legit xpath statement 2) xpath to a node - node exists 3) xpath to a node - node does not exist 4) other - like name(/root/node) |
#8
| |||
| |||
|
#9
| |||
| |||
|
#10
| |||
| |||
|
|
* David Thielen wrote in microsoft.public.dotnet.xml: The problem with that is a user can feed us anything for the xpath - including true(). What we really need is something that returns any of the following: 1) not a legit xpath statement 2) xpath to a node - node exists 3) xpath to a node - node does not exist 4) other - like name(/root/node) You can use the .Compile method which will return a XPathExpression object which has a returnType property of type XPathResultType which in turn will allow you to distinguish these cases. Evaluating the ex- pression will then tell you whether there are matching nodes. -- Björn Höhrmann · mailto:bjoern (AT) hoehrmann (DOT) de · http://bjoern.hoehrmann.de Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |