Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Tolls

Thread: Generating JAXB classes

  1. #1
    javaexp is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Generating JAXB classes

    Hi,

    My xml: http://www.javaexperience.com/catalog.xml

    I have an xml for which I want to generate JAXB classes. Unfortunately I don't have access to xsd for this xml.

    Could someone please share steps to generate JAXB classes for a xml. What I have tried is:

    1) Generate the xsd from this xml using XML to XSD Generater Online - xmlGrid.net

    2) Use the Maven JAXB plugin "org.jvnet.jaxb2_commons"

    The problem I faced with my approach was that:

    Since the xml has root element and one of the child element as same name, the JAXB processor fails on reaching the child "Catalog" tag. Even though it had successfully processed the root "Catalog" tag.

    Any pointers would of great help.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Generating JAXB classes

    That's because you have two Catalogs which are different things.
    How is JAXB supposed to know how to handle that?
    If they were in different namespaces then no problem, but there's no namespaces at all.

    No great surprise there isn't an xsd for this.
    Please do not ask for code as refusal often offends.

  3. #3
    javaexp is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Re: Generating JAXB classes

    @Tolls, thanks for confirming this. I think I don't have any option because this xml is sent by Verizon's Terremark cloud as response to one of the REST API call and I can't do anything with the xml as such.

    Probably I would look for json format of the response and try using json to java (hopefully that would work).

    This is what happens when you are dependent on the vendor.

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: Generating JAXB classes

    Quote Originally Posted by javaexp View Post
    This is what happens when you are dependent on the vendor.
    ... and not set down strict boundaries and demands when striking a deal with them.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Generating JAXB classes

    Quote Originally Posted by gimbal2 View Post
    ... and not set down strict boundaries and demands when striking a deal with them.
    Been there recently.
    Luckily I didn't have to deal with the 3rd party directly, but the chap next to me did.
    When asked where the xsd for their response data for their web service was (a RESTful one) the reply was "we don't need an xsd, it's just plain old xml".
    I couldn't help but laugh.
    Please do not ask for code as refusal often offends.

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: Generating JAXB classes

    Quote Originally Posted by Tolls View Post
    I couldn't help but laugh.
    I would have cried anyway because sooner or later, this type of shit comes to haunt you even if it starts out as someone else's problem. Usually around vacation time, or when the project goes down the toilet due to what you're laughing about and the other guy gets mysteriously "ill" for a long period of time.

    Long story short: its a nightmare waiting to strike when you don't expect it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Generating JAXB classes

    Ah, but in our position (especially mine as a contractor) we don't negotiate these things.
    Marketing (I believe) was the one who had already sorted out the contract with this 3rd party (it was for car parking). We had the job of wiring it into the system.
    All we could do was highlight the problems their set up was causing. And it did cause problems even before I left as their system was not costing things correctly, but at least our side of things was logging everything, so we could prove our code was doing what it should.

    Always keep an email trail, and log all interactions.
    :)
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: Generating JAXB classes

    Quote Originally Posted by Tolls View Post
    Always keep an email trail, and log all interactions.
    Amen!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Jaxb
    By unknownuser in forum Advanced Java
    Replies: 2
    Last Post: 08-14-2013, 10:55 AM
  2. JAXB not generating all classes
    By seethalrd in forum XML
    Replies: 4
    Last Post: 09-24-2010, 01:54 PM
  3. Replies: 0
    Last Post: 02-22-2010, 05:15 AM
  4. Replies: 0
    Last Post: 02-22-2010, 04:37 AM
  5. Jaxb
    By Paul Richards in forum XML
    Replies: 1
    Last Post: 08-03-2009, 09:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •