BigInteger
Friday, 5 April 2019 · 6 messages
AB
Andre Bovy5 Apr 2019 11:15 #
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é
MH
Martin Honnen5 Apr 2019 12:46 #
Quoted text · Andre Bovy · 17 lines
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 $sNot 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 $sruns fine as well but with BaseX I get the error you mentioned.
AB
Andre Bovy5 Apr 2019 15:41 #
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 :
Quoted text · Martin Honnen · 1 line
>> BigInteger:new("12345678901234567890”) returns an error
and
Quoted text · Martin Honnen · 1 line
>> 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é
Quoted text · Martin Honnen · 54 lines
> On 5 Apr 2019, at 12:46, Martin Honnen <martin.honnen at 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. > > >
CG
Christian Grün5 Apr 2019 15:52 #
Hi André,
Quoted text · Andre Bovy · 1 line
> 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
AB
Andre Bovy5 Apr 2019 16:01 #
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é
Quoted text · Christian Grün · 14 lines
> On 5 Apr 2019, at 15:52, Christian Grün <christian.gruen at 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
CG
Christian Grün5 Apr 2019 16:11 #
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
Quoted text · Andre Bovy · 27 lines
On Fri, Apr 5, 2019 at 4:01 PM Andre Bovy <andre.bovy at 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 at 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 >
Written for BaseX 9.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery