2

I have to define an XSD that describe the stub for some documents. There are some fields that are common and known from the start. Those are no issue. However, the exhaustive list of document types is not known, neither is the list of extra attributes that needs to be passed.

So far, I have a <data> element declared like this:

<xsd:complexType name="data">
  <xsd:sequence>
    <xsd:any minOccurs="0" />
  </xsd:sequence>
</xsd:complexType>

I do know that what will be in there will be a map of name and primitive types. And this list is intended to be enforced by some additional XSD provided in the xml, declared in the <data> element.
Is there a way to ensure that JAXB will properly convert the nested elements, without knowing in advance what will be the nested namespace?

gizmo
  • 11,819
  • 6
  • 44
  • 61
  • 1
    possible duplicate of [Serializing with JAXB and the Any](http://stackoverflow.com/questions/13941747/serializing-with-jaxb-and-the-any). https://jaxb.java.net/nonav/2.2.4/docs/api/javax/xml/bind/annotation/XmlAnyElement.html - one more reference. – Mikhail Jan 15 '14 at 09:11
  • Unfortunately, I think the proposed solution in the mentioned post is not applicable in my case as it imply that the unmarshaller can register upfront custom classes to use with the "lax" element. In my case, the known element are xsi primitives. So ideally I would have a list of JAXBElement instead of the ElementNSImpl I am currently able to get. – gizmo Jan 15 '14 at 15:40
  • 2
    Does this help: http://blog.bdoughan.com/2012/02/xmlanyelement-and-xmladapter.html – bdoughan Jan 15 '14 at 21:58
  • Somewhat, yes. Thanks. In the meantime, the requirements have changed and I can now accommodate with a simple map with xsi:type put on values to ensure proper unmarshalling. – gizmo Jan 17 '14 at 08:24

0 Answers0