[xstream-user] Advanced Xpath usage

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[xstream-user] Advanced Xpath usage

Geoffrey De Smet-3
[Previous mail failed according to smtp server]

Hi,

I am using Xstream to restore my testdata to my database on application
startup.
http://opensource2.atlassian.com/projects/spring/browse/SPR-1453


In my testDatabaseBackup.xml file, I have something like this:
<linked-list>
   <x.Company id="apache">
     ...
   </x.Company>
   <x.Order>
      <supplier reference="../../x.Company[1]"/>
   <x.Order>
</linked-list>

Works like a charm.


But I want to do this:
<linked-list>
   <x.Company id="apache">
     ...
   </x.Company>
   <x.Order>
      <supplier reference="/*/x.Company[@id='apache']"/>
   <x.Order>
</linked-list>

Which is allowed according to the XPath convention.
But it doesn't work.
How good does Xstream support XPath?

Even a simple absolute xpath doesn't work:
<supplier reference="/linked-list/x.Company[1]"/>


I am using the latest xstream jar with the DomDriver in J2SE 1.5:
XStream xstream = new XStream(new DomDriver()); // does not require XPP3

Thanks for any and all help,
Geoffrey

Reply | Threaded
Open this post in threaded view
|

RE: [xstream-user] Advanced Xpath usage

Jörg Schaible
Hi Geoffry,

Geoffrey De Smet wrote on Wednesday, November 09, 2005 1:43 PM:

[snip]

> Which is allowed according to the XPath convention.
> But it doesn't work.
> How good does Xstream support XPath?

[snip]

XStream is designed for fast serialization and deserialization. Since it does not make usage of most of the XPath features it has an own XPath implemenation that supports a *very* limited subset of XPath ... exactly for its own needs.

You might implement your own unmarshaller though, that uses a real XPath implementation. Set an own marshalling strategy with XStream.setMarshallingStrategy, derive from ReferenceByXPathMarshallingStrategy and overload the unmarshal method.

Regrads,
Jörg
Reply | Threaded
Open this post in threaded view
|

[xstream-user] Re: Advanced Xpath usage

Geoffrey De Smet-3
Thank you for your quick reply.

In my case I use it to configure my testData.
Because I have a lot of bi-directional references in composite
relations, I preferred Xpath for those over using ID_REFERENCES:

<Person> <!-- No need to define an id reference -->
   <Dog>
     <owner reference="../.."/>
   </Dog>
<Person>

However I also use defined elements, with an id, for association
relations, in which case absolute xpaths would be very usefull.

Enabling absolute xpaths, such as
/list/Person[1]
would already make a big improvement.


For now I 'll stick to ID_REFERENCES as it works well enough.
Thanks for a great library.

--
With kind regards,
Geoffrey De Smet

J?rg Schaible wrote:

> Hi Geoffry,
>
> Geoffrey De Smet wrote on Wednesday, November 09, 2005 1:43 PM:
>
> [snip]
>
>
>>Which is allowed according to the XPath convention.
>>But it doesn't work.
>>How good does Xstream support XPath?
>
>
> [snip]
>
> XStream is designed for fast serialization and deserialization. Since it does not make usage of most of the XPath features it has an own XPath implemenation that supports a *very* limited subset of XPath ... exactly for its own needs.
>
> You might implement your own unmarshaller though, that uses a real XPath implementation. Set an own marshalling strategy with XStream.setMarshallingStrategy, derive from ReferenceByXPathMarshallingStrategy and overload the unmarshal method.
>
> Regrads,
> J?rg
>