I am receiving a validation exception due to a double being serialized in the
form "2,3456" (thanks Germany), which seems to be causing an xpath to fail on
that value, likely because it is doing a numeric comparison ">". I understand
why this would be the case and I'm fine with the exception. My problem is that
this exception is not within the namespace of the saxon library or in the base
.net libraries. I found some documentation here: [http://msdn.microsoft.com
/en-us/library/system.componentmodel.dataannotations.validationexception.aspx]
(http://msdn.microsoft.com/en-
us/library/system.componentmodel.dataannotations.validationexception.aspx)
Am I to assume that this is the exception that is being thrown? Using latest
he version for .net.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This will be an instance of net.sf.saxon.type.ValidationException, which is a
Java class mapped to a .NET type using the IKVMC compiler. Ideally when you
use the Saxon.Api interfaces under .NET, all exceptions from the underlying
code should be mapped to something like Saxon.Api.StaticError or
Saxon.Api.DynamicError; however, I'm sure there are many cases where this is
not happening (it's difficult to do it systematically because of the lack of
strong exception handling in C#). If there are specific cases, however, then
please show the code you are running and the results that you get, and I will
try to improve it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok fair enough. Here is an odd example:
Xml:
<property name="PercentProcessorTime" value="99,294351" type="System.Single" unit="Percent"/>
XPath:
property
Result:
Error during processing:
net.sf.saxon.trans.XPathException: Required item type of first operand of '>'
is numeric. Cannot convert string "99,294351" to a double
Xml:
same
Xpath:
//property
Result:
Error during processing:
ValidationException: Cannot convert string "99,294351" to a double
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I could use reflection to inspect the type name of the exception but since it
looks like there is not a specific exception to catch, I will catch all and
just log it. Thanks. For anyone else encountering this issue with incorrect
serialization in .net of numeric values you can use the following
Convert.ToString(value, NumberFormatInfo.InvariantInfo). This will take any
unusual number formatting and convert it to a standard format that should be
compatible with xml types.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I assume you are using the XPath API (Saxon.Api.XPathSelector), though you
haven't actually said. I've now added some error catching to the methods in
this class so that they throw a Saxon.Api.DynamicError instead of the
underlying Java exception; the error handling is also better documented.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am receiving a validation exception due to a double being serialized in the
form "2,3456" (thanks Germany), which seems to be causing an xpath to fail on
that value, likely because it is doing a numeric comparison ">". I understand
why this would be the case and I'm fine with the exception. My problem is that
this exception is not within the namespace of the saxon library or in the base
.net libraries. I found some documentation here: [http://msdn.microsoft.com
/en-us/library/system.componentmodel.dataannotations.validationexception.aspx]
(http://msdn.microsoft.com/en-
us/library/system.componentmodel.dataannotations.validationexception.aspx)
Am I to assume that this is the exception that is being thrown? Using latest
he version for .net.
This will be an instance of net.sf.saxon.type.ValidationException, which is a
Java class mapped to a .NET type using the IKVMC compiler. Ideally when you
use the Saxon.Api interfaces under .NET, all exceptions from the underlying
code should be mapped to something like Saxon.Api.StaticError or
Saxon.Api.DynamicError; however, I'm sure there are many cases where this is
not happening (it's difficult to do it systematically because of the lack of
strong exception handling in C#). If there are specific cases, however, then
please show the code you are running and the results that you get, and I will
try to improve it.
Ok fair enough. Here is an odd example:
Xml:
<property name="PercentProcessorTime" value="99,294351" type="System.Single" unit="Percent"/>
XPath:
property
Result:
Error during processing:
net.sf.saxon.trans.XPathException: Required item type of first operand of '>'
is numeric. Cannot convert string "99,294351" to a double
Xml:
same
Xpath:
//property
Result:
Error during processing:
ValidationException: Cannot convert string "99,294351" to a double
I could use reflection to inspect the type name of the exception but since it
looks like there is not a specific exception to catch, I will catch all and
just log it. Thanks. For anyone else encountering this issue with incorrect
serialization in .net of numeric values you can use the following
Convert.ToString(value, NumberFormatInfo.InvariantInfo). This will take any
unusual number formatting and convert it to a standard format that should be
compatible with xml types.
I assume you are using the XPath API (Saxon.Api.XPathSelector), though you
haven't actually said. I've now added some error catching to the methods in
this class so that they throw a Saxon.Api.DynamicError instead of the
underlying Java exception; the error handling is also better documented.
Yes I was using XPathSelector as part of an editor I wrote for developing
xpath/xquery/xsd/xslt. Thanks for the quick responses!