On Feb 17, 2014, at 12:25 PM, Christian Grün christian.gruen@gmail.com wrote:
For the record, what I ended up going with was: https://github.com/openhie/openinfoman/blob/master/repo/csd_base_library.xqm... Lines 14-26.
...interesting!
Thanks for that, it did the trick. I am curious what I was doing wrong with the BigInteger attempt?
Right now, xs:integer values in BaseX are limited to signed long values, which is compliant with the XQuery spec, but which is also why
I thought that was for xs:int, but not xs:integer which is of arbitrary length. In other words: http://www.w3.org/TR/xmlschema11-2/#integer versus http://www.w3.org/TR/xmlschema11-2/#int
the Java conversion of BigInteger will yield invalid values. There could be ways to improve the situation:
a) raise errors when a Java value is too large to be converted to a BaseX XQuery item b) allow integers larger than long values by representing BaseX xs:integer values as internal BigInteger instances c) avoid Java calls whenever possible...
Personally, I generally tend to recommend c); not just because it means least effort for us, but also because it's not possible to define a 100% mapping between XQuery and Java data types. Nevertheless, in parallel, I'll also think a bit more about options a) and b).
Really all I needed for my use case was to call the toString() method on the BigInteger instance, but I couldn’t seem to do that without the implicit cast to xs:integer. What about something along the lines of: BI:new() returns a basex:binary as it’s type and leave it to the user to handle any explicit casting?
Hope this helps,
Yes. Thanks.
Christian
Cheers, -carl
On Feb 13, 2014, at 7:10 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Carl,
Any suggestions?
there may be several solutions; one of them looks as follows:
let $uuid := xs:hexBinary(translate(random:uuid(),'-','')) let $bytes := convert:binary-to-bytes($uuid) ! xs:decimal(if(. < 0) then .+256 else .) return fold-left($bytes, 0, function($a, $b) { $a * 256 + $b })
Hope this helps, Christian
Cheers, -carl
declare namespace BI = "java:java.math.BigInteger";
declare function uuid_oid() { let $uuid := translate(random:uuid(),'-','') let $bigInt := concat('2.25.',BI:new($uuid, xs:int(16) )) return $bigInt
};
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk