Discussion:
[saxon] Creating a sequence of XdmAtomicValue
Christophe Marchand
2017-03-31 09:39:19 UTC
Permalink
Hello,

I want to create a sequence of XdmAtomicValue ; for example, this : (4,
5, 6) where 4, 5& 6 are xs:int.

XdmValue.append(XdmValue) does not change the size of the sequence.

How should I do ?

Thanks,
Christophe
Michael Kay
2017-03-31 10:17:38 UTC
Permalink
You can use XdmValue.append() - just remember that it creates a new immutable XdmValue rather than modifying the one supplied as the argument. This also means that creating a value of size N this way has performance O(N^2).

This way you would do

XdmValue.wrap(new XdmAtomicValue(1)).append(new XdmAtomicValue(2)).append(new XdmAtomicValue(3)).

So you're probably better off using the constructor

public XdmValue(Iterable<? extends XdmItem> items)

which allows you to do

new XdmValue(Arrays.asList(new XdmAtomicValue[]{new XdmAtomicValue(1), new XdmAtomicValue(2), new XdmAtomicValue(3)}))

You can probably do something much smarter with Java 8 streams but I haven't really mastered that yet.

Michael Kay
Saxonica
Post by Christophe Marchand
Hello,
I want to create a sequence of XdmAtomicValue ; for example, this : (4,
5, 6) where 4, 5& 6 are xs:int.
XdmValue.append(XdmValue) does not change the size of the sequence.
How should I do ?
Thanks,
Christophe
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
https://lists.sourceforge.net/lists/listinfo/saxon-help
Christophe Marchand
2017-03-31 10:36:49 UTC
Permalink
Thanks a lot !

Christophe
Post by Michael Kay
You can use XdmValue.append() - just remember that it creates a new immutable XdmValue rather than modifying the one supplied as the argument. This also means that creating a value of size N this way has performance O(N^2).
This way you would do
XdmValue.wrap(new XdmAtomicValue(1)).append(new XdmAtomicValue(2)).append(new XdmAtomicValue(3)).
So you're probably better off using the constructor
public XdmValue(Iterable<? extends XdmItem> items)
which allows you to do
new XdmValue(Arrays.asList(new XdmAtomicValue[]{new XdmAtomicValue(1), new XdmAtomicValue(2), new XdmAtomicValue(3)}))
You can probably do something much smarter with Java 8 streams but I haven't really mastered that yet.
Michael Kay
Saxonica
Post by Christophe Marchand
Hello,
I want to create a sequence of XdmAtomicValue ; for example, this : (4,
5, 6) where 4, 5& 6 are xs:int.
XdmValue.append(XdmValue) does not change the size of the sequence.
How should I do ?
Thanks,
Christophe
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
https://lists.sourceforge.net/lists/listinfo/saxon-help
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
https://lists.sourceforge.net/lists/listinfo/saxon-help
Loading...