Hi Chistian,
I am trying to use a very Big Integer in BaseX (9.1.2)
With this value : declare namespace BigInteger = "java:java.math.BigInteger";
BigInteger:new("12345678901234567890”)
I received : Cannot convert xs:string to xs:integer: "12345678901234567890”.
The java method that I used returns a BigInteger, but I just need the value as a String.
I tried : BigInteger:toString(BigInteger:new("12345678901234567890”)) without success (same error)
Is there a workaround to this behaviour ? without writing a Java class.
Thank you in advance André
Am 05.04.2019 um 11:15 schrieb Andre Bovy:
Hi Chistian,
I am trying to use a very Big Integer in BaseX (9.1.2)
With this value : declare namespace BigInteger = "java:java.math.BigInteger";
BigInteger:new("12345678901234567890”)
I received : Cannot convert xs:string to xs:integer: "12345678901234567890”.
The java method that I used returns a BigInteger, but I just need the value as a String.
If you have the BigInteger returned from your Java method and want it as an XQuery string try
let $s as xs:string := BigInteger:toString($valueFromJavaMethod)
or
let $s as xs:string := $valueFromJavaMethod => BigInteger:toString()
e.g. a complete example that works for me with BaseX 9 is
declare namespace BigInteger = "java:java.math.BigInteger";
let $s as xs:string := BigInteger:TEN() => BigInteger:toString() return $s
Not sure about that problem with the constructor, with Saxon
declare namespace BigInteger = "java:java.math.BigInteger";
let $s as xs:string := BigInteger:new("12345678901234567890") => BigInteger:toString() return $s
runs fine as well but with BaseX I get the error you mentioned.
Thank you for your answer.
I tried the different syntax and had the same error. I don’t think that the error comes from the constructor.
In fact :
BigInteger:new("12345678901234567890”) returns an error
and
BigInteger:new("1234567890123456789”) runs correctly
I think that BaseX try to match the java type “BigInteger" into a XQuery type "xs:integer” which is not possible when the value is too big. And no syntax allows to avoid this mapping.
Is it possible ?
Thank you in advance André
On 5 Apr 2019, at 12:46, Martin Honnen martin.honnen@gmx.de wrote:
Am 05.04.2019 um 11:15 schrieb Andre Bovy:
Hi Chistian,
I am trying to use a very Big Integer in BaseX (9.1.2)
With this value : declare namespace BigInteger = "java:java.math.BigInteger";
BigInteger:new("12345678901234567890”)
I received : Cannot convert xs:string to xs:integer: "12345678901234567890”.
The java method that I used returns a BigInteger, but I just need the value as a String.
If you have the BigInteger returned from your Java method and want it as an XQuery string try
let $s as xs:string := BigInteger:toString($valueFromJavaMethod)
or
let $s as xs:string := $valueFromJavaMethod => BigInteger:toString()
e.g. a complete example that works for me with BaseX 9 is
declare namespace BigInteger = "java:java.math.BigInteger";
let $s as xs:string := BigInteger:TEN() => BigInteger:toString() return $s
Not sure about that problem with the constructor, with Saxon
declare namespace BigInteger = "java:java.math.BigInteger";
let $s as xs:string := BigInteger:new("12345678901234567890") => BigInteger:toString() return $s
runs fine as well but with BaseX I get the error you mentioned.
Hi André,
I think that BaseX try to match the java type “BigInteger" into a XQuery type "xs:integer” which is not possible when the value is too big.
Exactly, that’s why.
If there’s a chance to write your code in plain XQuery, then I would definitely recommend that. You indicated that you need the result as string: Do you want to check if your input is a valid integer value?
Best, Christian
In fact, I am converting an X509 certificate (Base64) into XML and some of the properties of the certificates are BigInteger.
No problem, I just write a small class which will do the translation into String
Perhaps a topic to add in the CRYPTO module
Thank you, André
On 5 Apr 2019, at 15:52, Christian Grün christian.gruen@gmail.com wrote:
Hi André,
I think that BaseX try to match the java type “BigInteger" into a XQuery type "xs:integer” which is not possible when the value is too big.
Exactly, that’s why.
If there’s a chance to write your code in plain XQuery, then I would definitely recommend that. You indicated that you need the result as string: Do you want to check if your input is a valid integer value?
Best, Christian
You could also have a look at the Binary and Conversion Module:
http://docs.basex.org/wiki/Binary_Module http://docs.basex.org/wiki/Conversion_Module
On Fri, Apr 5, 2019 at 4:01 PM Andre Bovy andre.bovy@gmail.com wrote:
In fact, I am converting an X509 certificate (Base64) into XML and some of the properties of the certificates are BigInteger.
No problem, I just write a small class which will do the translation into String
Perhaps a topic to add in the CRYPTO module
Thank you, André
On 5 Apr 2019, at 15:52, Christian Grün christian.gruen@gmail.com wrote:
Hi André,
I think that BaseX try to match the java type “BigInteger" into a XQuery type "xs:integer” which is not possible when the value is too big.
Exactly, that’s why.
If there’s a chance to write your code in plain XQuery, then I would definitely recommend that. You indicated that you need the result as string: Do you want to check if your input is a valid integer value?
Best, Christian
basex-talk@mailman.uni-konstanz.de