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/

Similar Messages

  • 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/

  • About generating Java classes from XSD Schema ???

    I need a powerfull tool to generate Java classes from XML Schema. I want that generated classes to have the option to validate XML(to be JAXP1.2 compliant).
    I used XML Spy 5.4 but the generated classes can't validate an XML file.
    Can you help me with other tools that:
    - generate Java classes from XSD
    - generate sample XML from XSD
    - are JAXP1.2 compliant(validate a XML file with a schema)
    Thanks.

    You can also use Castor: http://www.castor.org
    It generates classes from XML Schemas and enables data
    binding without writing any line of a fuckin SAX
    parser :-)I evaluated Castor and JAXB and while JAXB isn't perfect, it's got some things over Castor. Castor almost looks abandonded when I go to the site. The documentation just sort of trails off.

  • Error when generating Java Classes from XSD

    I'm getting the following error when using oragc to generate Java classes from a schema:
    Error: Schema Class Generator failed to generate classes. oracle.xml.parser.schema.XSDException: Invalid facet 'pattern' in element 'simpleType'
    Any thoughts?
    Here's the part where it is getting the error:
    +111 <!-- Timestamp Type - Timezone portion is required and fractional seconds are prohibited -->
    +112 <xsd:simpleType name="TimestampType">
    +113 <xsd:annotation>
    +114 <xsd:documentation>Base type for a date and time stamp</xsd:documentation>
    +115 </xsd:annotation>
    +116 <xsd:restriction base="xsd:dateTime">
    +117 <xsd:pattern value="[1-9][0-9]{3}\-.+T[^\.]+(Z|[\+\-].+)" />
    +118 </xsd:restriction>
    +119 </xsd:simpleType>

    I would recommend using JAXB instead of the Oracle class generator. This will give a standards based object-to-XML platform.
    Oracle provides two JAXB implementations: one in the TopLink product, and the other in the XDK.
    For an example of using TopLink JAXB see:
    http://www.oracle.com/technology/products/ias/toplink/technical/tips/jaxb/index.htm
    TopLink also provides the ability to map existing Java objects to an existing XML Schema, for an example of this see:
    http://www.oracle.com/technology/products/ias/toplink/technical/tips/ox/index.htm
    -Blaise

  • 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

    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.

  • Errors generating Java classes from XML schema

    I received the following errors when generating Java classes from the schema located at: http://imsproject.org/xsd/ims_qti_rootv1p1.xsd and http://imsproject.org/xsd/ims_xml.xsd
    XML Spy v4 claims that the schema is well-formed and valid. Could this be a problem with the class generators, or is XML Spy not telling the truth?
    Thanks.
    D:\IMS_QTI\Java>java -classpath .;lib/xmlparserv2.jar;lib/xschema.jar;lib/classgen.jar oracle.xml.classgen.oracg -schema ims_qti_rootv1p1.xs
    d -outputDir src\com\icld\qti -package com.icld.qti -comment
    file:/D:/IMS_QTI/Java/ims_qti_rootv1p1.xsd<Line 235, Column 21>: XSD-2209: (Error) Duplicated definition for: 'attr.view'
    file:/D:/IMS_QTI/Java/ims_qti_rootv1p1.xsd<Line 303, Column 21>: XSD-2209: (Error) Duplicated definition for: 'grp.labels'
    file:/D:/IMS_QTI/Java/ims_qti_rootv1p1.xsd<Line 1834, Column -12236>: XSD-2209: (Error) Duplicated definition for: 'qtimetadatafield'
    file:/D:/IMS_QTI/Java/ims_qti_rootv1p1.xsd<Line 1834, Column -9642>: XSD-2209: (Error) Duplicated definition for: 'typeofsolutionType'
    file:/D:/IMS_QTI/Java/ims_qti_rootv1p1.xsd<Line 2252, Column -3019>: XSD-2026: (Error) Invalid attribute 'use' in element 'attribute'
    Error: Schema Class Generator failed to generate classes. oracle.xml.parser.schema.XSDException: Duplicated definition for: 'attr.view'

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Jinyu Wang ([email protected]):
    Which version are you using? I can't reproduce the error with 9.0.2B version.<HR></BLOCKQUOTE>
    Thanks for having a look at the problem. I am using the 9.0.2.0B version with Java 2 Standard Edition Build 1.3.1-b24. The classgen -version option returns 9.0.2.0b-beta - and xmlparserv2.jar and xschema.jar are from the same distribution. Running the corresponding DTD from the same source work fine - I'm just havinf this problem with the XSD. Anything else I should look at?

  • 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.

  • 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.

  • Generating XML instance from XSD

    Hi,
    I want to know ( java program etc ) to generate XML instance from XSD. How tools ( XML Spy, Oxygen ) generate sample XML file from XSD. What APIs can be used for generating XML from XSD and what APIs are used for checking If XML instance conforms to a XSD? Is it big deal to implement it?
    Thanks in advance
    Sandeep

    To validate xml against XSD , I found I can use the existing parsers( using JAXP which has SAX and DOM APIs ) in current JDKs and validate. I still did not find the best way to generate xml from XSD and how tools like xml spy and oxygen generates sample xml file from xsd.
    Thanks
    Sandeep

  • 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>

  • How to produce Java class from xsd programmatically?

    As titled, I want to generage Java class/interface from xml schema via a program. There is a tool "xjc" that can do this manually.
    I saw a sample that generates xsd file from Java class programmatically, I am figuring out if there is such a API to do the similar thing vice versa.
    Thank you in advance!

    You may want to check out this Java EE 5 Tutorial: http://docs.oracle.com/javaee/5/tutorial/doc/bnbah.html
    It has an example of generating JAXB Java classes from an XML schema.
    Can you provide a sample xsd schema and the resulting Java class/classes you want to have produced?
    XMLBeans can use an xsd and generate Java classes for containing/manipulating XML objects, though I don't think that is what you are wanting.
    You can also write an XSLT stylesheet that generates Java classes based on parameters that you provide to the stylesheet but there is no xsd schema involved. We used this at a major national bank to produce Java classes for batch processing of files sent/received between the bank and third pary companies. The Java classes generated were used to read/write delimited files, xml files and fixed format files to/from Java bean classes with the necessary getters/setters for manipulating the data.
    Without a sample of what you are trying to doi it is hard to offer much help.

  • Generate JFaces jsp from xsd

    Hi all,
    I have an XML schema file, I'm able to generate all classes with sdo EMF project and now I want to generate jsp faces automaticaly .
    It'is possible to do that? If yes, why?
    Thank you in advance
    Mj

    Thanks dvohra_09.
    Now my problem is if I have to generate HTML form by xsd file and after user input the form completely I have to generate xml file also.
    So for now I have to do 2 step are :
    - Generate HTML form by xsd file
    - Get data from form to generate xml file
    Have anyone can suggest me? I much appreciate it.
    Thanks.

  • Can't fill ByteArray in EJB-Method with generated Model-Class from WD-Model

    Hello everybody,
    i try to call an ejb-method with data from an FileUpload-UI-Element in WD. The EJB-Method is receiving the byte-data to create a document in KM via a Web-Service.
    The ebj-methid has the following signature:
    public FObject putFileDataSimple (byte [] btContent, String fullFileName, String username, String password)
    After importing the Model and creating a context node i have the following structure:
    Request_X_putFileDataSimple
    +---btContent (Node)
          +-- item
    + fullFileName
    + username
    + password
    btContent is of the generated Type Byte_Item, which is itself a generated Model-Class of modelClassType ARRAY
    item is of Type byte
    But i simply have problems to fill the context node (or the binded model-object). i tried different ways and looked at thread [https://www.sdn.sap.com/irj/scn/thread?messageID=1954223] but i cant get it work.
    So my Method in WD looks like this to fill the structure and start the ejb-method:
    public boolean putKMDataSimple( com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource fin )  {
    try
      wdContext.currentRequest_X_putFileDataSimpleElement().setFullFileName("abc");
      wdContext.currentRequest_X_putFileDataSimpleElement().setUsername("def");
      wdContext.currentRequest_X_putFileDataSimpleElement().setPassword("xxx");
      byte[] buffer = new byte[1];
      InputStream in = fin.read(false);
      int i = 1;
      int j = 0;
      while (i!=-1)
         i = in.read(buffer);
         if (i!=-1)
           Byte_Item bi = new Byte_Item(mAlf);     // mAlf ist global defined Model-Class-Instance
           bi.setItem(buffer[0]);
            wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().addBtContent(bi);
      wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().execute();
    Doing this results in Error-Messages like:
    Model-Object is not a complex type for every byte added this way.
    And finally an IllegalArgumentException at java.lang.reflect.Array.set(Native Method)
    The second way i tried is:
    public boolean putKMDataSimple( com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource fin )  {
    try
      wdContext.currentRequest_X_putFileDataSimpleElement().setFullFileName("abc");
      wdContext.currentRequest_X_putFileDataSimpleElement().setUsername("def");
      wdContext.currentRequest_X_putFileDataSimpleElement().setPassword("xxx");
      byte[] buffer = new byte[1];
      ArrayList<Byte> btlist = new ArrayList<Byte>();
      InputStream in = fin.read(false);
      int i = 1;
      int j = 0;
      while (i!=-1)
         i = in.read(buffer);
         if (i!=-1)
              btList.add(buffer[0]);
      wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().setBtContent(btList);
      wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().execute();
    Trying so results in:
    java.lang.ClassCastException: class java.lang.Byte:null incompatible with interface com.sap.tc.cmi.model.ICMIModelClass:library:com.sap.tc.cmi(at-sign)[email protected]@alive
    whenn calling the setBtContent Method
    I don't what to do now to fill the context/model-object the right way.
    Any helpfull hints are very welcome
    Edited by: Matthias Hayk on Dec 1, 2008 5:51 PM
    Edited by: Matthias Hayk on Dec 2, 2008 10:56 AM

    Ok Vesselin and thanx for your idea,
    so i adapted the source in the way you told like the following:
                     ArrayList<Byte_Item> btlist = new ArrayList<Byte_Item>();
                     byte[] buffer = new byte[1];
                     InputStream in = fin.read(false);
                     int i = 1;
                     int j = 0;
                     while (i!=-1)
                          i = in.read(buffer);
                          if (i!=-1)
                               // Byte gelesen
                               Byte_Item bi = new Byte_Item(mAlf);
                               bi.setItem(buffer[0]);
                               btlist.add(bi);
                               j++;
                     wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().setBtContent(btlist);     
                     wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().execute();
    This results also in the following Exception when exceuting the WS-proxy:
    execute
    [EXCEPTION]
    java.lang.IllegalArgumentException
    at java.lang.reflect.Array.set(Native Method)
    at com.sap.tc.webdynpro.model.ejb.model.EJBGenericModelClassExecutable.getInputParameters(EJBGenericModelClassExecutable.java:215)
    at com.sap.tc.webdynpro.model.ejb.model.EJBGenericModelClassExecutable.execute(EJBGenericModelClassExecutable.java:112)

  • Xrpcc modeler error when trying to generate stub classes from a WSDL

    I'm trying to generate JAX-RPC stub classes (both client and server side) from a WSDL in which one of the message parts references a complexType element defined in the <types> section of the WSDL. Here is my little WSDL document:
    <?xml version="1.0" encoding="UTF-8"?>
    <definitions name="Book_Def"
    targetNamespace="myTypes"
    xmlns:tns="myTypes"
    xmlns:xsd1="myTypes"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <types>
    <xsd:schema targetNameSpace="myTypes"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="Book" type="xsd1:BookType"/>
    <xsd:complexType name="BookType">
    <xsd:all>
    <xsd:element name="authors" type="xsd:string" maxOccurs="10"/>
    <xsd:element name="preface" type="xsd:string"/>
    <xsd:element name="price" type="xsd:float"/>
    </xsd:all>
    </xsd:complexType>
    </xsd:schema>
    </types>
    <message name="runMyPgm">
    <part name="book" type="xsd1:Book"/>
    </message>
    <message name="getPgmResponse">
    <part name="result" type="xsd:string"/>
    </message>
    <portType name="MyPgmIFPortType">
    <operation name="runMyPgm">
    <input message="tns:runMyPgm"/>
    <output message="tns:getPgmResponse"/>
    </operation>
    </portType>
    ... Binding stuff
    </port>
    </service>
    </definitions>
    I've tried many combinations of defining my complex type and input message and whenever I run xrpcc using this WSDL as input, I get a Error: Modeler error: invalid entity name: Book (in namespace "myTypes"). Sorry if this is a dumb question, but what am I doing wrong in my <types> or <message> definitions to cause this error? I've had some luck generating stubs when the part types are all simple types, but I've not had any luck with getting a <complexType> definition accepted by xrpcc. Thanks in advance for any help you can offer.

    Yes you can specify type mapping in configuration file and probably this will solve the problem, but I've never tested this approach. Perhaps I'm not advanced user. Actually the serializerFactory and deserializerFactory are a little vague for me:(

Maybe you are looking for