Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] OXM and combining xml elements

Hi,

I have a need to produce XML according to the following format:

<root>
  <ListOfElements>
    <Element>
      <ElementOfTypeA>
      </ElementOfTypeA>
    </Element>
    <Element>
      <ElementOfTypeA>
      </ElementOfTypeA>
    </Element>
    <Element>
      <ElementOfTypeB>
      </ElementOfTypeB>
    </Element>
    <Element>
      <ElementOfTypeB>
      </ElementOfTypeB>
    </Element>
  </ListOfElements>
</root>

ElementOfTypeA and ElementOfTypeB are based on different Java classes. The extra 'Element' elements do not make any sense, but I have to generate them like that.

I tried multiple combinations where I either provided ElementOfTypeA and ElementOfTypeB from my Java model through different List attributes or with a combined list using a superclass.

In the first case, I used these formats:
<xml-elements java-attribute="listWithElementsOfTypeA">
<xml-element-wrapper name="ListOfElements/Element/" />
</xml-elements>

and:
<xml-element java-attribute="listWithElementsOfTypeA"
                                          name="ElementOfTypeA">
  <xml-element-wrapper name="ListOfElements/Element" />
</xml-element>

and also:
<xml-element java-attribute="listWithElementsOfTypeA"
                                  name="Element/ElementOfTypeA">
  <xml-element-wrapper name="ListOfElements" />
</xml-element>

But MOXy combines the 'Element' elements and I end up with this:
<root>
  <ListOfElements>
    <Element>
      <ElementOfTypeA>
      </ElementOfTypeA>
      <ElementOfTypeA>
      </ElementOfTypeA>
      <ElementOfTypeB>
      </ElementOfTypeB>
      <ElementOfTypeB>
      </ElementOfTypeB>
    </Element>
  </ListOfElements>
</root>

In the second case, MOXy added an xsi-type attribute to the Element elements. I used this then:
<xml-elements java-attribute="elementKoppelingen">
  <xml-element type=ElementOfTypeA name=Element />
  <xml-element type=ElementOfTypeB name=Element />
  <xml-element-wrapper name="ListOfElements" />
</xml-elements>

How can I prevent MOXy from combining my Element elements?

Thanks a lot in advance,
Julius


Back to the top