Re: [Simple-support] Streaming root elements
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2009-05-26 16:07:18
|
Hi,
This is caused by StAX rather than Simple. There may be a StAX implementation that does not use a buffering input stream out there, perhaps the Woodstox StAX implementation? Also you could create a single root and write all nodes as children of that root. If none of these are satisfactory then you will have to wrap the input stream in something that will give all bytes up to the final element. I might add this to the org.simpleframework.xml.util package myself as others have asked the same.
Regards,
Niall
--- On Tue, 5/26/09, Niklas Hag <nik...@ni...> wrote:
> From: Niklas Hag <nik...@ni...>
> Subject: [Simple-support] Streaming root elements
> To: sim...@li...
> Date: Tuesday, May 26, 2009, 5:59 AM
> Hi,
> I'm new at this - and I'm probably doin' some trivial
> error.
>
> I have a very simple implementation and I like to put some
> Simple-java
> classes on a stream, in sequence.
>
> In the below example the XML is put on a stream and I would
> have hoped that
> the persister should manage to parse the stream as several
> sequential XML
> root nodes (i.e. AnnotatedTestClass instances)
> But the first invocation of persister.read(clazz,
> inputStream) empties the
> stream but however just one object is returned.
> The next attempt to invoke the method will block,
> naturally.
>
> How do I get around this? Is it possible or have I
> misunderstood the usage
> of stream as input?
>
>
> Many thanks in advance
>
> - Niklas
>
>
> // XML is
> "<annotatedTestClass>
> <num>77</num>
> <name>test1</name>
> </annotatedTestClass><annotatedTestClass>
> <num>77</num>
> <name>test1</name>
> </annotatedTestClass><annotatedTestClass>
> <num>77</num>
> <name>test1</name>
> </annotatedTestClass>"
>
> // Sample code
> persister = new org.simpleframework.xml.core.Persister();
> for (int iter=0; iter<3; iter++) {
> AnnotatedTestClass obj2 =
> (AnnotatedTestClass)persister.read(AnnotatedTestClass.class,
> inputStream);
> // etc ...
> }
>
>
> // Class impl
> @Root(strict=false)
> public class AnnotatedTestClass {
>
> public AnnotatedTestClass() {
> }
>
> @Element(required=false)
> private Integer num;
>
> @Element(required=false)
> private String name;
>
> public Integer getNum() {
> return num;
> }
>
> public void setNum(Integer num) {
> this.num = num;
> }
>
> public String getName() {
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> @Override
> public boolean equals(Object obj) {
> AnnotatedTestClass
> other = (AnnotatedTestClass)obj;
> boolean eq =
> Equals.equals(this.num, other.getNum());
> eq &=
> Equals.equals(this.name, other.getName());
> return eq;
> }
>
>
>
>
>
> ------------------------------------------------------------------------------
> Register Now for Creativity and Technology (CaT), June 3rd,
> NYC. CaT
> is a gathering of tech-side developers & brand
> creativity professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity,
> Processing, &
> iPhoneDevCamp asthey present alongside digital heavyweights
> like Barbarian
> Group, R/GA, & Big Spaceship. http://www.creativitycat.com
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
|