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.

The web service project will add additional server runtime libraries to the classpath thus resolving the jaxb dependencies, in the case of a dynamic web project, you'll have to manage that with the JPA facet and eclipselink, or by adding the Moxy jars seperately. However, if you want to use the target runtime libraries create a user-library and reference the following server libraries: (from Server Install Dir\modules) glassfish.jaxb_"version".jar, glassfish.jaxb.xjc_"version".jar, javax.activation_"version".jar, javax.xml.bind_"version".jar, javax.xml.stream_"version".jar.

Similar Messages

  • Customize names of generated JAXB classes

    I have a peculiar requirement. We have been using JAXB1.0 in our project to parse XMLs. External binding files were used to provide proper names for the generated JAXB classes. Now, I have an xml that looks something like this:
    //sample xml. Original format is much bigger
    <b>
    <MasterTag>
    <attr id="123">Value1</attr>
    <attr id="736">Value2</attr>
    <attr id="900">value3</attr>
    </MasterTag>
    </b>
    There's a property file which has key value pairs for the attr id
    Eg:
    <b>
    123=CompanyID
    736=CompanyAddress
    900=CompanyPinCode
    </b>
    Is it possible to generate JAXB classes names based on the attr id value? These values finally need to persisted in the db. JAXB is the preferred technology.
    Any other ideas are also welcome. Thanks.

    I might be misunderstanding your question, but if you control the single large schema, it would be simple to define the things that you want to treat specially as either individual elements or complexTypes inside the single schema file. Using psuedo-schema, say you have something like this now:
    <xs:element name='Information'>
      <xs:complexType>
        <xs:sequence>
          <xs:element name='Header'>
              <!-- your definition here -->
          </xs:element>
          <xs:element name='Item' maxOccurs='unbounded'>
              <!-- your definition here -->
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>You can change that to:
    <xs:element name='Information'>
      <xs:complexType>
        <xs:sequence>
          <xs:element ref='Header'/>
          <xs:element name='Item' maxOccurs='unbounded'>
              <!-- your definition here -->
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element name='Header'>
      <!-- your definition here -->
    </xs:element>That should produce distinct classes for your Information and Header elements. You similary can break out the Item and Trailer elements.

  • Problem Generating JAXB Classes

    I am using Eclipse (Enterprise Pack) and want to generate JAXB classes from a schema. I right click on the schema, select Generate JAXB classes - fill in package name, next and get the error:
    java.lang.NoClassDefFoundError: com/sun/tools/xjc/XJCFacade
    Caused by: java.lang.ClassNotFoundException: com.sun.tools.xjc.XJCFacade
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
    Exception in thread "main"
    Am I missing a library?
    Steve Watson

    The web service project will add additional server runtime libraries to the classpath thus resolving the jaxb dependencies, in the case of a dynamic web project, you'll have to manage that with the JPA facet and eclipselink, or by adding the Moxy jars seperately. However, if you want to use the target runtime libraries create a user-library and reference the following server libraries: (from Server Install Dir\modules) glassfish.jaxb_"version".jar, glassfish.jaxb.xjc_"version".jar, javax.activation_"version".jar, javax.xml.bind_"version".jar, javax.xml.stream_"version".jar.

  • Generating JAXB classes from an XSD

    Hi All,
    Can anyone please tell me how to generate Jaxb classes for xsd in eclipse , or in ant .
    Thanks and Regards

    Try here as well
    https://jaxb.dev.java.net/

  • How do I unmarshal to only a portion of generated JAXB classes?

    I have an XML schema that is laid out something like this:
    <Information>
    <Header/>
    <Item> (Unbounded)
    <Trailer/>
    </Information>
    I receive files that have thousands of items in them. Because of the size of the files, I must use SAX to parse the file.
    I need to unmarshal each file and store the results in a database after following some conditional logic. It is not practical to unmarshal a 500 MB file.
    What I have been doing is using a SAX DefaultHandler to strip out each <Item> element.
    I had to create a separate schema for just the <Item> element so that I could use JAXB's xjc to generate a set of classes to unmarshal each <Item> element to.
    This works great, but it is a hassle to maintain. You see, I also need to unmarshal the <Header> element. So I have to create a separate schema for that as well. So then I end up with two sets of JAXB classes, with lots of duplication. Plus, if I have any complex types that are referenced in both the <Header> and the <Item>, then I have to include those in each sub schema.
    What I want to know is:
    Is it possible to just generate ONE set of JAXB classes for the main schema, and then unmarshal the stripped out <Item> element to just the corresponding Item in the generated JAXB classes?
    This is a complicated topic, and I hope I've been clear. Basically, I have to create these <Header> and <Item> schemas by hand every time the main schema changes, and I want to get away from that.

    I might be misunderstanding your question, but if you control the single large schema, it would be simple to define the things that you want to treat specially as either individual elements or complexTypes inside the single schema file. Using psuedo-schema, say you have something like this now:
    <xs:element name='Information'>
      <xs:complexType>
        <xs:sequence>
          <xs:element name='Header'>
              <!-- your definition here -->
          </xs:element>
          <xs:element name='Item' maxOccurs='unbounded'>
              <!-- your definition here -->
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>You can change that to:
    <xs:element name='Information'>
      <xs:complexType>
        <xs:sequence>
          <xs:element ref='Header'/>
          <xs:element name='Item' maxOccurs='unbounded'>
              <!-- your definition here -->
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element name='Header'>
      <!-- your definition here -->
    </xs:element>That should produce distinct classes for your Information and Header elements. You similary can break out the Item and Trailer elements.

  • Generating JAXB classes from XSD

    I am generating java classes using JAXB binding from XSDs. I organized the classes into 2 packages say package1 and package2
    The XSD to create the package2 is dependent on package1. So I do an include package1.xsd in package2.xsd. With this I am running into an issue with JDeveloper while generating the classes. When I generate classes using package2.xsd, all package1.xsd classes are also generated in the same package. So, I have to manually delete these classes from package1.xsd and add import statements from package1 where required.
    Is there a solutiion/work around available for suppressing duplicate class generation? Any help would be greatly appreciated.

    Try here as well
    https://jaxb.dev.java.net/

  • Mapping Generated JAXB Classes to JAVA Classes

    Hi,
    i�m writing a framework to allow building swing components from xml files. So i use JAXB to generate the stubs and then in
    my JAVA app i do an unmarshal process to get the jaxb elements. Then i process all the elements in the jaxb tree and
    i create the corresponding swing components (i.e. JPanel, GridLayout, JButton, JTextField, etc). This is very annoying,
    since each component has different properties and this leads to many if statements which just make my code messy
    and not reusable.
    Could someone give me an advice of how i could make this solution more elegant?
    Thanks for any ideas,
    Chris

    Hi,
    Can you please let me know if you found a solution? I have the same exact problem. I have pretty solid collection of similar questions in the NET, but not a single answer yet... Keep searching...
    Thanks!
    Rouben.
    P.S can you please CC your answer to [email protected]?

  • JAXB classes generation

    Hi all,
    I have 4 XMLSchema files and need to generate JAXB classes out of them. But most of the nodes like header parts of request and response of messages are same in structure. If I generate classes in 4 different packages how can I separate out the common node .java classes so that setting / getting repetition is avoided in my application.
    Thanks in advance.
    JoyBoy

    There are some good examples here:
    http://java.sun.com/webservices/jaxb/users-guide/jaxb-using.html

  • JAXB to generate java classes for XSD.

    Hi
    I have a XSD, which is importing other couple of xsds in it, tried to generate java classes using xjc, it is throwing error.
    C:\vittal\Project\received\development-1\da_xsd>xjc -p com daAuthoring.xsd
    parsing a schema...
    [ERROR] Property "Alt" is already defined. Use <jaxb:property> to resolve thi
    s conflict.
      line 42 of file:/C:/vittal/Project/received/development-1/da_xsd/commonElement
    s.xsd
    [ERROR] The following location is relevant to the above error
      line 2205 of file:/C:/vittal/Project/received/development-1/da_xsd/daCommonEle
    ments.xsd
    Failed to parse a schema.Please let me know how to fix this issue.

    Thanks for information,
    I do understand xml well, and having basic knowledge on XSD.
    1. can i generate a java classes for a xsd which is including other XSDs.
    2. how to overwrite the issue, using annotation, point me to a location where i will get more information, that will be great help.
    here is my xsd.
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:dctm="http://www.documentum.com" elementFormDefault="qualified">
         <xs:import namespace="http://dita.oasis-open.org/architecture/2005/" schemaLocation="ditaarch.xsd"/>
         <xs:import namespace="http://www.documentum.com" schemaLocation="dctmAttrs.ent.xsd"/>
         <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
         <xs:group name="alt">
              <xs:sequence>
                   <xs:element ref="alt"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="desc">
              <xs:sequence>
                   <xs:element ref="desc"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="title">
              <xs:sequence>
                   <xs:element ref="title"/>
              </xs:sequence>
         </xs:group>
         <!-- Elements in tblDecl.mod -->
         <xs:group name="colspec">
              <xs:sequence>
                   <xs:element ref="colspec"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="entry">
              <xs:sequence>
                   <xs:element ref="entry"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="row">
              <xs:sequence>
                   <xs:element ref="row"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="tbody">
              <xs:sequence>
                   <xs:element ref="tbody"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="tgroup">
              <xs:sequence>
                   <xs:element ref="tgroup"/>
              </xs:sequence>
         </xs:group>
         <xs:group name="thead">
              <xs:sequence>
                   <xs:element ref="thead"/>
              </xs:sequence>
         </xs:group>
    </xs:schema>

  • JAXB problem generating java classes

    I'm doing some integration and have received a schema from the vendor the other day. When I try to generate java classes with the jaxb compiler I get this output
    parsing a schema...
    [ERROR] Property "Value" is already defined.
      line 14 of jar:file:/C:/win32app/Java/jdk6/lib/tools.jar!/com/sun/xml/internal/xsom/impl/parser/datatypes.xsd
    [ERROR] The following location is relevant to the above error
      line 384 of file:/C:/code/sca-ecr.xsd
    Failed to parse a schema.
        <xsd:complexType name="options">
            <xsd:sequence>
                <xsd:element name="option" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
    (Line 384)                  <xsd:attribute name="value" type="xsd:string"/>
                            </xsd:extension>
                        </xsd:simpleContent>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>So, googling about this I came across these to articles that almost describes my problem.
    http://weblogs.java.net/blog/kohsuke/archive/2005/05/compiling_mathm_1.html
    https://jaxb.dev.java.net/guide/Dealing_with_errors.htmlAdding the this code did not help. Downloading JAXB 2.1.4 did not help, adding the -extension parameter still same result.
            <xsd:annotation>
              <xsd:appinfo>           
                <jaxb:property name="someAttribute" />
              </xsd:appinfo>
            </xsd:annotation>      Why is jaxb failing ? Could it be that and attribute is not allowed to be called "value" ?
    Any answers will do
    regards abq

    Well, after hours of digging I found a solution which actually was right in front of me the whole time.
    This is how I edited the schema.
        <xsd:complexType name="options">
            <xsd:sequence>
                <xsd:element name="option" maxOccurs="unbounded" >
                    <xsd:complexType>
                        <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
                               <xsd:attribute name="value" type="xsd:string" >
                                  <xsd:annotation><xsd:appinfo>
                                    <jaxb:property name="realValue" />
                                  </xsd:appinfo></xsd:annotation>
                                 </xsd:attribute>
                            </xsd:extension>
                        </xsd:simpleContent>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>Before, I placed the <xsd:annotation> tag efter the first line but inside the <xsd:attribute> made much better if you would like it to work.
    When marshling an @XmlRoot object will produce valid xml code. So even though that the server have a different xml schema, they will be able to talk to each other.
    abq

  • JAXB 1 : generating simpleTypes classes

    Sorry, I posted an uncompleted message.
    Hello, I'm new to JAXB technology.
    Since I'm working with j2sdk 1.4 I c'ant use JAXB 2, so I'm using JAXB 1.0.6.
    When I call the xjc ant task, my java classes are generated... buy simple types do not generate any java class.
    Let's say I have the following xsd:
    <xs:complexType name="EXAMPLE">
    <xs:sequence>
    <xs:element name="market-type" type="po:market-type"/>
    </xs:sequence>
    </xs:complexType>
    <xs:simpleType name="MARKET-TYPE">
    <xs:restriction base = "xs:string">
    <xs:enumeration value = "PRIM"/>
    <xs:enumeration value = "SECOND"/>
    </xs:restriction>
    </xs:simpleType> After xjc compilation I have a EXAMPLE Java class, but its element "market-type" is a String and not a MARKET-TYPE as I expected.
    Is it normal? Can I customize the output in order to generate java classes for simpleTypes?

    The base data type of the simpleType MARKET-TYPE is xsd:string.

  • JAXB not generating correct class definition

    Hi,
    I am using JAXB 2.0 and the JAXB plugin for Eclipse 3.x.
    The problem I have is that when I run XJC on my XSD file the class definition for
    a particular class is not what I am expecting. The class only defines 1 get method instead of three. While I am expecting to see getX getY and getZ I am seeing only 1 method getXAndgetYAndgetZ. Here is a snippet of the XSD file:
         <xs:element name="Sql">
              <xs:complexType>
                   <xs:sequence minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="Query"/>
                        <xs:element ref="Table" maxOccurs="unbounded"/>
                        <xs:element name="Database" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>I have defined the Table element in the XSD.
    In this case my generated Sql class has the following method:
    public List<JAXBElement<String>> getQueryAndTableAndDatabase() {
            if (queryAndTableAndDatabase == null) {
                queryAndTableAndDatabase = new ArrayList<JAXBElement<String>>();
            return this.queryAndTableAndDatabase;
        }Is there a problem with my XSD file or am I omitting a parameter when running XJC? Any help greatly appreciated

    LDAPLoginModule uses the jackrabbit UserManagerImpl to create user's in CRX (CQ), not the CQ5 implementation which is disappointing. Have to manually add the sling:resourceType.

  • JAXB - Generated Java Classes error

    Hi,
    I am having a problem generating java classes given the follow snippet from a DTD. The ImplemenationData class that is generated does not include ImplementationPlatform and ProgramParameters as attributes. Instead, it includes these two elements in the PredicatedLists and then generates a content exception when those elements are not found. Can anyone tell me why these two elements are not being generated as attributes with the associated setter/getter methods to go with them? The ExeOptions, DllOptions and ExternalOptions are being generated properly and included in the PredicatedLists as they should be. Any help would be greatly appreciated.
    <!ELEMENT ImplementationPlatform           (#PCDATA)>
    <!ELEMENT ProgramParameters                (#PCDATA)>
    <!ELEMENT ImplementationData
         (ImplementationPlatform,
         ProgramParameters,
         (ExeOptions
         |DllOptions
         |ExternalOptions))>
    <!ELEMENT ExeOptions
         (PathAndFileName,
         WorkingDirectoryName?,
         Environment?,
         InheritEnvironment,
         StartInForeGround?,
         AutomaticClose?,
         WindowStyle?,
         RunInXTerm?)>
    <!ELEMENT DllOptions
         (PathAndFileName,
         EntryPointName,
         ExecuteFenced?,
         KeepLoaded?)>
    <!ELEMENT ExternalOptions
         (ServiceName,
         ServiceType,
         InvocationType,
         ExecutableName,
         ExecutableType,
         IsLocalUser,
         IsSecurityRoutineCall,
         CodePage?,
         TimeoutPeriod,
         TimeoutInterval?,
         IsMappingRoutineCall,
         MappingType?,
         ForwardMappingFormat?,
         ForwardMappingParameters?,
         BackwardMappingFormat?,
         BackwardMappingParameters?)>

    Just a thumb suck but, have you tried placing the defintitions after the declarations instead of before.
    Dave

  • How to omit xmlns from generated Java classes

    Hi,
    I'm using JAXB and xjc to generate Java classes from xsd fils. I've noticed that when marshalling these Java classes to XML string, there are few xmlns attributes that (as far as I concern :-))
    "waste" space on the generated xml (space is critical resource in our application). Is there a way to order the Marashaller to omit these xmlns attributes from the generated files?
    I tried to edit the generated xml string. I removed the xmlns attributes, but unmarshall it back to Java objects failed...
    Thanks for any help,
    Barak.

    If the xmlns is specified in the xsd, it is also required in the xml. If you do not want it, however you can remove it from your xsd and then generate your xml

  • Cannot Use JaxB classes in ADF application.

    Hi
    I am using JDeveloper 11.1.1.6
    I am trying to call the Oracle Business Rules (OBR) Ruleset from the frontend.
    When I call a simple rule only using Java facts (facts are object references of classes which are used in OBR)  as input, the Rules are verified and executed correctly.
    After that I tried to give XML Facts as input the application is facing ClassNotFoundException.
    To access the XML facts I had to add the XML Fact class known as JAXB_CLASSES into the Libraries and Classpath of Project Properties.
    First I tried to call the OBR rules containing the XML Facts / Jaxb_classes from the page and it throwed ClassNotFoundException while deploying the application.
    Next I tried to invoke the Jaxb_classes from main method and it worked fine.
    My Question is : How can I access JAXB Classes in an ADF View Controller Project/ Application?
    Thanks,
    Nigel.

    I am adding the JAXB_classes into the application in the Backend and the code for intialising is also written in the Backens.
    Still, the application is throwing a exception like
    <RuleSession> <logIt> The symbol 'generated.ParametersType' is undefined.
    at line 7 column 14 in main
    <RuleSession> <logIt> UndefinedException: The symbol 'generated.ParametersType' is undefined.
      at line 7 column 14 in main
    <RuleSession> <logIt> The symbol 'generated.ParametersType' is undefined.
    at line 7 column 14 in main
    <RuleSession> <logIt> UndefinedException: The symbol 'generated.ParametersType' is undefined.
      at line 7 column 14 in main
    oracle.rules.sdk2.exception.SDKException: RUL-05186: error setting up rule session pool for decision point

Maybe you are looking for

  • Have a problem in Photo Elements 4

    I am trying to make a 4fold greeting card, opening like a book.  I have placed a photo on the front, and written text for the inside which was placed on the right hand side of the inside.  I would also like to place text on the left hand inside page,

  • Issue while installing Project Controls application in Unifier 10.1

    Hi , I am installing Unifier 10.1 under weblogic 12c. Everything went fine till deployment and logged in as Site Administrator to install the Project Controls application .While trying to install the application , after a certain period of processing

  • What is the main use of text elements in program.

    Hi Experts, Can any body please explain, why we have to maintain text elements in program. is it only for avoiding hot coding or else any thing. Please explain.And why we have to avoid hot coding with text elements. regards, developer.

  • Can transfer to playlist, but doesnt show up in library      please help

    I have several songs that i am unable to transfer directly to the library.... they are easily dragged/dropped into a playlist in iTunes, but dont show up in the main library. Also they show up as a playlist on my iPhone 4, but again are not found ANY

  • Converting Mixed Footage

    Hey there, I've been given a real mixed bag of footage to edit in FCP and I just wanted to ask what the best thing to do is. The files I have are: H264 1280x720 10fps 640x360 25fps 568x320 30fps 1280x720 29.97fps 1280x720 24fps 854x480 29.97fps 564x3