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

XPathNavigator.ValueAsBoolean - no exception

Hi;

How can I tell if I can call XPathNavigator.ValueAsBoolean safely - without
throwing an exception. I want to take one course of action if the value can
be interpreted as a boolean.

But I din't want to do it using try/catch - I think having exceptions be
thrown when the code is operating normally is very bad - both from a
performance point of view and because it signifiys an error.

--
thanks - dave
Nov 12 '05 #1
6 1394
Hi dave,

Currently we are looking for someone to help you on this issue, we will
reply to you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 12 '05 #2
David Thielen wrote:
How can I tell if I can call XPathNavigator.ValueAsBoolean safely - without
throwing an exception. I want to take one course of action if the value can
be interpreted as a boolean.

But I din't want to do it using try/catch - I think having exceptions be
thrown when the code is operating normally is very bad - both from a
performance point of view and because it signifiys an error.


I don't think XPathNavigator provides such functionality. The idea is
that when using ValueAsXXX methods you can be sure about node type, e.g.
because XML is valid.
As a workaround you can use Boolean.TryParse method, which doesn't throw
an exception when values cannot be converted to boolean:

if (Boolean.TryParse(navigator.Value, out myvalue))
//parsed ok
else
//not boolean value

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Nov 12 '05 #3
Hello;

My problem is customers can throw any xml at us and we have an if (Value is
Boolean) piece of logic. I think your solution will fix it - will post back
either way.

--
thanks - dave
"Oleg Tkachenko [MVP]" wrote:
David Thielen wrote:
How can I tell if I can call XPathNavigator.ValueAsBoolean safely - without
throwing an exception. I want to take one course of action if the value can
be interpreted as a boolean.

But I din't want to do it using try/catch - I think having exceptions be
thrown when the code is operating normally is very bad - both from a
performance point of view and because it signifiys an error.


I don't think XPathNavigator provides such functionality. The idea is
that when using ValueAsXXX methods you can be sure about node type, e.g.
because XML is valid.
As a workaround you can use Boolean.TryParse method, which doesn't throw
an exception when values cannot be converted to boolean:

if (Boolean.TryParse(navigator.Value, out myvalue))
//parsed ok
else
//not boolean value

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com

Nov 12 '05 #4
:(

I am in J# and I can't call TryParse - I assume because java does not
support ref parameters.

--
thanks - dave
"Oleg Tkachenko [MVP]" wrote:
David Thielen wrote:
How can I tell if I can call XPathNavigator.ValueAsBoolean safely - without
throwing an exception. I want to take one course of action if the value can
be interpreted as a boolean.

But I din't want to do it using try/catch - I think having exceptions be
thrown when the code is operating normally is very bad - both from a
performance point of view and because it signifiys an error.


I don't think XPathNavigator provides such functionality. The idea is
that when using ValueAsXXX methods you can be sure about node type, e.g.
because XML is valid.
As a workaround you can use Boolean.TryParse method, which doesn't throw
an exception when values cannot be converted to boolean:

if (Boolean.TryParse(navigator.Value, out myvalue))
//parsed ok
else
//not boolean value

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com

Nov 12 '05 #5
TryParse method is only available in .NET framework 2.0. Besides, there is
no way to judge whether a value is boolean without try to parse it and gets
exception.

http://msdn2.microsoft.com/en-us/library/khxs34ek

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #6
That's what I was afraid of.

--
thanks - dave
"Kevin Yu [MSFT]" wrote:
TryParse method is only available in .NET framework 2.0. Besides, there is
no way to judge whether a value is boolean without try to parse it and gets
exception.

http://msdn2.microsoft.com/en-us/library/khxs34ek

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Pearson | last post by:
Hi My function receives an XPathNavigator object. From here I need to build a DataSet to load into SQL Server (using SQLXML adaptor). Does anyone have an idea on the most efficient way to...
7
by: David Thielen | last post by:
Hi; Is there a way from an XPathNavigator object to get an xpath string that will, when used in a Select(xpath) on the underlying base/root XPathNavigator return the same XPathNavigator? In...
1
by: David Thielen | last post by:
Hi; How do I handle the following: XPathNavigator nav = ...; String str = nav.SelectSingleNode("floats/@ok").Value; // works fine - returns 1.3 nav.SelectSingleNode("floats/@ok == 1.3");...
12
by: David Thielen | last post by:
Hi; I have an element: <space> </space> When I call SelectSingleNode() on it, the InnerXml is a 0 length String, not a String containing 1 space. Any ideas?
2
by: JSheble | last post by:
I'm integrating with a customer application, and in their assembly, when I call a method it returns data to us as an XPathNavigator object. I can parse the various elements I need out of this...
4
by: Andy Fish | last post by:
Hi, I can't figure out for the life of me how to select nodes using a namespace in XpathNavigator. For example: XPathDocument doc = new XPathDocument("file.xml"); XPathNavigator nav =...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
4
by: Bruce Sandeman | last post by:
Hi, Does anyone know how to serialize an XPathNavigator object? I have tried the following but it moans that the xpn does not have a parameterless constructor. XPathNavigator xpn =...
2
by: =?Utf-8?B?Tm9yZW1hYw==?= | last post by:
Hi. Using VS2005, .NET 2.0. I have an xml document that I want to go through and set the values on attributes of elements. The elements are complex types defined in my schema (xsd) files. ...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.