[Home] [By Thread] [By Date] [Recent Entries]
Hi,
I want to test if a string (obtained through reading a piece of unparsed document) is numeric, without raising an error so that subsequent operations can be done. Let's assume variable x contains the string to test. We cannot do simply xs:integer($s), or any casting like that, because it would produce an fatal runtime error when not numeric. So previously I was doing: string(number($x)) = "NaN" It is quite clear what the test wants to do, but it relies on "Not a Number" been represented by the "NaN" string. It is the default, but can be changed. Then at maintenance stage, if someone changes number to format-number with another representation of NaN this could fail. So now I'm using: number($x) = number($x) It's a bit unclear, but it is obvioulsy true when $x is an number, including + and - infinity (see spec.) In fact, as the specification states, it is only false when $x is not a number, because NaN is never equal to NaN! This test works fine (false is NaN, opposite to the first test), but it looks a little bit hard for maintenance. Any better idea or advise ? Best Regards. Alain BENEDETTI
|

Cart



