JAXB Practical issues.


XML & Web services: JAXB Practical issues.

  1. JAXB Practical issues. (1 messages)

    I have a typical XML Schema (XS), where there is very deep nesting of complex types( I generated this XSD from XML instance using SPY). When I generate classes using JAXB(xjc), along with other classes, one class gets generated with n number of static inner classes in it(say
    around 50). when I compile(JAVAC) this class, very long classnames
    gets generated as :
    Abcd$Efgh$Ijkl$Mnop$Qrst.......... and sometimes it becomes so long that MS WINDOWS( XP) does not like the file name and starts behaving abnormally with the file. I am facing this problem especially when I use something like eclipse or WSAD to compile the code. Please suggest a work around if you have come across this issue!!
    As a work around, I thought of generating jaxb code from DTD, where hierarchy is not this much nested. BUT DTD is not fully supported -
    what is the future of DTD support? will be removed at all? remember most of the XML docs still follow DTDs. Will the stable releases support DTD based generation?
    Thanks in advance
  2. Working around JAXB nesting[ Go to top ]

    Hi Ranjith,
    If your XSD has complex types nested in complex types, then JAXB will generate the classes in that structure using inner classes. I personally don't like the such deep nesting of inner classes, as it makes it difficult to code, document and maintain.

    To workaround this problem, have your XSD define global complex types. This is so that JAXB will generate them as individual classes. I believe there's a option in SPY to generate your complex types as global types when reverse engineering your XML to XSD.