Hi Greg,

Sergei is in vacation this week, I will try to answer your question.

transformOutInterceptor.setOutTransformElements(Collections.singletonMap("{http://something}Child1";,
 "")) should remove only Child1 element with all his children.
Not sure why it results removing Parent children, are you sure with that test?

What you basically need to delete and elements and insert it in different order 
is something like this:

transformOutInterceptor.setOutTransformElements(Collections.singletonMap("{http://something}Child2";,
 ""));
transformOutInterceptor.setInAppendElements(Collections.singletonMap("{http://something}Child1";,
 "{http://something}Child2=Another Value"));

If it not enough you can use XSLT Feature 
http://cxf.apache.org/docs/xslt-feature.html to apply any XSLT script to your 
request/response.

Other alternative is to create own interceptor, put it to POST_PROTOCOL phase 
and sort elements in message payload as you want.

Regards,
Andrei.

> -----Original Message-----
> From: Greg Barker [mailto:[email protected]]
> Sent: Samstag, 25. Mai 2013 02:09
> To: [email protected]
> Subject: Re: Specifying order of XML elements at runtime?
> 
> Thanks for the quick reply Sergey!
> 
> I'm having a bit a trouble with the suggested solution though, almost
> certainly a pilot error on my part I assume.
> 
> XML before:
> <Container xmlns="http://something";>
>     <Parent>
>         <Child1>Some Value</Child1>
>         <Child2>Another Value</Child2>
>     </Parent>
> </Container>
> 
> So I tried:
> transformOutInterceptor.setOutDropElements(Collections.singletonList("{
> http://something}Child1";));
> 
> Which results in:
> <Container xmlns="http://something";>
>     <Parent>
>         Some Value
>         <Child2>Another Value</Child2>
>     </Parent>
> </Container>
> 
> Got rid of the element...but not the value. So I tried the "deep-drop"
> described on that link:
> transformOutInterceptor.setOutTransformElements(Collections.singletonM
> ap("{
> http://something}Child1";, ""));
> 
> Which resulted in:
> <Container xmlns="http://something";>
>     <Parent/>
> </Container>
> 
> What am I screwing up? I basically just want to end up with:
> <Container xmlns="http://something";>
>     <Parent>
>         <Child2>Another Value</Child2>
>         <Child1>Some Value</Child1>
>     </Parent>
>           </Container>
> 
> Many Thanks!
> Greg
> 
> 
> On Fri, May 24, 2013 at 3:36 AM, Sergey Beryozkin
> <[email protected]>wrote:
> 
> > Hi
> >
> > On 23/05/13 22:02, Greg Barker wrote:
> >
> >> Hello -
> >>
> >> I'm using the Apache CXF WebClient for a project, and the REST API I
> >> am interacting with has a requirement that XML elements are sent in a
> >> specific order, and "correct" order can change depending on certain
> >> settings that are not known at compile time.
> >>
> >> I've found that the XmlType.propOrder annotation allows me to specify
> >> the order in which I want the XML elements to appear at compile time.
> >> This works great. The problem is that I need to be able to change
> >> this order at runtime, and I cannot figure out a way to do that
> >> without resorting to ugly/hacky solutions that modify the annotation at
> runtime.
> >>
> >> Is there an easy way to specify XML element order dynamically at
> runtime?
> >>
> >>  Try Transformation feature:
> >
> > http://cxf.apache.org/docs/**transformationfeature.html<http://cxf.apa
> > che.org/docs/transformationfeature.html>
> >
> > Use outDropElements and outAppendElements properties.
> >
> > Suppose you have the following produced by default:
> > <request>
> >   <a/>
> >   <b/>
> > </request>
> >
> > if needed, you can get <a/> dropped with outDropElements and then
> > added immediately after <b/> with outAppendElements.
> >
> > If that has to be set up dynamically then add the feature or its
> > interceptors from the code, similarly to
> > http://cxf.apache.org/docs/**transformationfeature.html#**
> > TransformationFeature-
> **Configuringthefeaturefromtheco**de<http://cxf.
> > apache.org/docs/transformationfeature.html#TransformationFeature-
> Confi
> > guringthefeaturefromthecode>
> >
> > HTH, Sergey
> >
> >  Thanks!
> >> Greg
> >>
> >>
> >

Reply via email to