I'm currently working with an XML Schema that has <xsd:annotation>
/<xsd:documentation>
on most types and elements. When I generate Java Beans from this XML Schema, then the Javadoc of those Beans only contains some generic generated information about the allowed content of the type/element.
I'd like to see the content of the <xsd:documentation>
tag in the relevant places (for example the content of that tag for a complextType should show up in the Javadoc of the class generated to represent that complexType).
Is there any way to achieve this?
Edit: this XML Schema will be used in a WSDL with JAX-WS, so this tag might be appropriate as well.
Edit 2: I've read about <jxb:javadoc>
. From what I understand I can specify that either in a separate JAXB binding file or directly in the XML Schema. That would almost solve my problem. But I'd rather use the existing <xsd:documentation>
tag, since Javadoc is not the primary target of the documentation (it's information about the data structure primarily and not about the Java Beans generated from it) and to allow non-JAXB tools to access the information as well. Providing the documentation in both <jxb:javadoc>
and xsd:documentation>
"feels" wrong, because I'm duplicating data (and work) for no good reason.
Edit 3: Thanks to the answer by Pascal I realized that I already have half a solution: The <xsd:documentation>
of complexType
s is written to the beginning of its Javadoc! The problem is still that only that complexType
s is used and simpleType
s (which can also result in a class) and elements are still Javadoc-less.
I've never been able to get regular
xsd:documentation
to be placed in the java source except if and only if it was a Complex Type. Documentation for elements, simple types, etc are ignored.So, I end up using
jxb:javadoc
. To do so, include the definition ofxmlns:jxb="http://java.sun.com/xml/ns/jaxb"
in your<xsd:schema>
element.Add a child to
<xsd:complexType>
or<xsd: element>
or<xsd:attribute>
:Where XXX is either "class" or "property".
For a package you write a child to
xsd:schema
Writing HTML document requires bracketing with
<![CDATA[ --- ]]>
(EDIT: While writing my answer, the question has been edited by the OP so I'm updating it accordingly)
In my case, javadoc was the only target so it was acceptable to use
jxb:javadoc
. But your update makes perfect sense and, actually, I totally agree with you. Sadly, I never found an ideal solution for the situation you describe (so I'll follow this question very carefully). Maybe you could use something like xframe to generate documentation fromxsd:documentation
, but this doesn't answer the question.This just isn't possible with the JAXB reference implementation. Even if you were to try to write an XJC plugin, you'd find that the plugin API is given no reference to the Schema definition, so there's no way to extract this information.
Our only hope is that a future version of JAXB fixes the situation. There's an open feature request here.
I find the following techniques work pretty well for adding JavaDoc headers to Java element classes (generated from XML schemas). I nest the JavaDoc in tags defined in the jax-b namespace, nested within the xml schema annotation and appinfo tags. Note the jaxb namespace defines types of documentation tags; I use two of there: the class and the property tags. defined in the following namespace: xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
1) To document a class, I use a jaxb "class" tag in the following sequence:
2) To document an element, I use the "property" tag as follows:
3) I use the same set of tags to document attributes:
4) To document a choice, I use the property jaxb tag, and I document the choice.
Attempting to document the individual choices here would fail, since this tag produces an untyped list.