Hi Michael,

Michael Mogley wrote:

> Thanks, Jörg!  That was it.  One thing I noticed is the referencing only
> works if I unmarshal from the root node.  If I descend into any of the
> children (moveDown), I again get the 'invalid reference' error.  Not sure
> if this is by design.  For anyone having a similiar issue, my new working
> code is below:
> 
> public static void main(String[] args)
>   {
>     try
>     {
>       String xml = StringUtils.join(new String[] {
>         "<list>",
>         "  <typeA/>",
>         "  <typeA/>",
>         "  <typeB>",
>         "    <items>",
>         "      <typeA reference=\"../../../typeA[2]\"/>",
>         "    </items>",
>         "  </typeB>",
>         "</list>"
>       }, "\n");
> 
>       // Read objects.
>       XStream xstream = new XStream();
>       xstream.alias("typeA", TypeA.class);
>       xstream.alias("typeB", TypeB.class);
> 
>       HierarchicalStreamReader xstreamReader = new XppReader(new
> StringReader(xml), XmlPullParserFactory.newInstance().newPullParser());
> 
>       for (Object nextObject : (List)xstream.unmarshal(xstreamReader))
>       {
>         LOG.info("read: {}", nextObject);
>       }
>     }
>     catch (Throwable t)
>     {
>       LOG.error(t.getMessage(), t);
>     }
>   }

The MarshallingStrategy is still the old one, so references do not work 
between the calls. There's no real difference to your first code snippet. 
You have to look at the last test that uses the custom MarshallingStrategy.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to