Hi!
Generating Java classes with XJC from HL7v3 XSD causes problems that were mentioned on this list and not only here. For example, EnGiven - class for given name - can’t properly marshall/unmarshall XML because there is no content i.e. text between <given> and </given>.
I know that Groovy could handle that but true Java lovers might be interested in my solution. I’m not JAXB/XJC expert and the solution is dirty.
I’ve used XDS from IPF (commons/ihe/hl7v3/src/main/resources/schema/HL7V3/NE2008) and modified datatypes-base.xsd, adding context attribute in ANY type:
<xs:complexType name="ANY" abstract="true">
. . .
<xs:attribute name="content" type="xs:string" use="optional"/>
</xs:complexType>
Then generation:
xjc -quiet multicacheschemas -b bindings.xjb
(bindings.xjb increases EnumMaxMembers).
This command will generate subdirectory org/hl7/v3 with all classes. In generated ANY.java I’ve modified:
@XmlAttribute(name = "content")
protected String content;
into:
@XmlValue
protected String content;
Usage:
ObjectFactory factory = new ObjectFactory();
EnGiven given = factory.createEnGiven();
given.setContent("Jack");
Find attached files that were modified.
If you know better way then let me know.
Thomas