1

I know we can apply an XSLT stylesheet to an XML Schema document. The stylesheet could generate an HTML manual by extracting the Documentation nodes in the desired language. Does anyone know if JAXB has similar functionality?

Thanks

user2167013
  • 321
  • 1
  • 3
  • 12

1 Answers1

0

JAXB has a schema compiler (XJC) which processes the schema and generates schema-derived classes. XJC supports a mechanism of plugins. Plugins can look into the "schema components" which produce individual classes and properties.

So yes, there is something similar in JAXB world.

See also this write-up on XJC internals.

Hubbitus
  • 4,481
  • 2
  • 37
  • 42
lexicore
  • 39,549
  • 12
  • 108
  • 193
  • This answer, while technically correct, is misleading. To unmarshal an XML Schema using JAXB, you'd need an XML Schema describing XmlSchema (you can find this on some W3C page) with the addition of all places where documentation nodes can crop up. Only then will unmarshalling with JAXB produce an object tree and you'll be able to locate the documentation snippets. --- I think it would be preferable to unmarshal using a generic XML Reader and process the resulting Node tree. – laune Sep 10 '14 at 11:25
  • @laune I don't quite agree. I specifically did not focus on unmarshalling the XML Schema with JAXB since I don't think it is a good idea (see XSOM https://xsom.java.net/ for this). The OP only asked about similarities. – lexicore Sep 10 '14 at 11:38
  • It is the "yes, there is something similar" which appears to be a *positive answer* to OP's question. Your comment plays another tune ("[not] a good idea"), so I take it you'd now rather answer "no" to OP's question? (Or, possibly, a "yes, but don't do it".) – laune Sep 10 '14 at 11:46
  • @laune You have to distinguish JAXB and XJC here. No, it's not a good idea to unmarshal XML schema with JAXB. Yes, it is often a good idea to compile schemas with XJC and yes you can process schema annotations in this case. – lexicore Sep 10 '14 at 12:25
  • As xjc extracts xs:annotation and xs:appinfo (e.g., for bindings) it is conceivable that you write an xjc plugin to extract any other xs:annotation. But then you have this in the context of an xjc compilation, and have to add some code to xjc to get that data in the shape you need. A *very* roundabout way, as compared to a simple XSLT. – laune Sep 10 '14 at 12:37