Subsitution problem in JAXB

I need to use jaxb to unmarshal some xml snippet like this:
<Request type="type1">
<a/>
<b/>
</Request>
<Request type="type2">
<c/>
<d/>
</Request>
The body of element "Request" depends on the value of attribute type
Though there is a substitution in JAXB My problem is there is no root element for substitution body.

Thanks for the reply,
Yes I tried the any element option. But i was able to use xs:any for only 1 element. We are not able to use the xs:any more than once.
Or i have to specify the tag name and give the type as any. But in this case i will be mentioning the tag name which i dont want to.

Similar Messages

  • Problem in JAXB for processing XML files

    hello
    I have been working on a project where i need to process data in XML format. the flow goes thus
    I have 28 data elements that i need to represent as a XML so i compile the schema files and generate the class files for each of the tags and thus i can use the get and set methods to read and write to a XML file respectively(example getName and setName)......
    Now the problem is that my coding is done if i change my xml file and add say 2 more tags how do i handle it in my code.........
    1>Do i have recomplie the schema file and generate new class files every time the xml structure changes. can i avoid this recompiling process and use a one time genrated class files even if the xml structure changes.
    2>Now i have hard coded the get and set methods for processing the xml file if i add new tags to my xml i wouldnt have the get set methods for the new tags in my code(say i add a new tag as Phone then i wouldnt have the codes getPhone and setPhone called in my code and this tage was added after the coding was done)........how do i handle this situation. Is is possible that i can get and set data without using these methods and use some sort of a dynamic way of getting and setting data.............
    3>Any other approach available to meet the above requirements other than JAXB.
    Please help for the above problem
    Thank you

    hi,
    i had written a xml and schema to validate.
    my xml would be
    <output>
    <table>
    <row>
    <column></column>
    <column></column>
    </row>
    </table>
    <document>
    <properties>
    </properties>
    <contents>
    </contents>
    </document>
    <table>
    <row>
    <column></column>
    <column></column>
    </row>
    </table>
    <document>
    <properties>
    </properties>
    <contents>
    </contents>
    </document>
    <table>
    <row>
    <column></column>
    <column></column>
    </row>
    </table>
    <document>
    <properties>
    </properties>
    <contents>
    </contents>
    </document>
    </output>
    schema should validate : each table should contain atleast one row element and each row element should have atleast one column. similarly, each document should have atleast one properties and contents element.
    if any of these things occur. for ex: if there is no row element in table, i need to delete the table tag. similary if there is no properties/content or both element in document it should delete the corresponding document from the xml.
    i tried for table if there is no row element am getting the line number of the </table> tag, based on that am deleting the table element. if there is no properties tag and contents tag is there. am getting the line number for <contents>start tag, with which i could not able to delete the whole document.
    can anybody plz help me out for this requirement

  • Parsing Problem in JAXB

    Hi, I am getting run time exception. I have kept all 4 jar files in classpath..
    Exception::javax.xml.bind.JAXBException: Provider com.sun.xml.bind.ContextFactor
    y_1_0_1 not found
    - with linked exception:
    [java.lang.ClassNotFoundException: com.sun.xml.bind.ContextFactory_1_0_1]
    Exception in thread "main" java.lang.NullPointerException
    at com.veritas.ProcessItem.readItem(ProcessItem.java:117)
    at com.veritas.ProcessItem.<init>(ProcessItem.java:86)
    at com.veritas.ProcessItem.main(ProcessItem.java:126)
    So wht could be the reason??
    Thanks
    Chintan

    I've the same problem, but in java 6.
    The jaxb jars are included in jdk6, right?

  • Problems using JAXB in windows(Failed to load Main-Class manifest)

    Friends,
    I am trying to use JAXB in windows environment. I have already included rt and xjc jar files in my system classpath.
    I have sucessfully created java files using the xjc compiler(without the xjs map file). They rock!!
    But I am facing problems while creating .xjs file from my dtd. I tried looking into previously discussed topics, with no help. :(
    my command line:
    java -jar C:\jaxb-1.0-ea\lib\jaxb-rt-1.0-ea.jar mySchemaFile.dtd
    This is what i get :
    Failed to load Main-Class manifest attribute from
    C:\jaxb-1.0-ea\lib\jaxb-rt-1.0-ea.jar
    Please help, if you have come across this or similar issue..
    Or let me know how you create a .xjs file.
    Any idea what is the main file class in jaxb-rt-1.0-ea.jar that creates a xjs file ?
    All/any help appreciated. Thanks in advance.

    Hi,
    You cannot use xjs files with the JAXB Beta RI.
    This has been mentioned at http://java.sun.com/xml/jaxb
    "Note that this version is not API-level compatible with the previous released version of the specification and DTD schemas are no longer supported."
    You can generate code using the xjc binding compiler for schema documents.
    Pls let me know if you have more questions
    Thanks,
    Bhakti
    Friends,
    I am trying to use JAXB in windows environment. I have
    already included rt and xjc jar files in my system
    classpath.
    I have sucessfully created java files using the xjc
    compiler(without the xjs map file). They rock!!
    But I am facing problems while creating .xjs file from
    my dtd. I tried looking into previously discussed
    topics, with no help. :(
    my command line:
    java -jar C:\jaxb-1.0-ea\lib\jaxb-rt-1.0-ea.jar
    mySchemaFile.dtd
    This is what i get :
    Failed to load Main-Class manifest attribute from
    C:\jaxb-1.0-ea\lib\jaxb-rt-1.0-ea.jar
    Please help, if you have come across this or similar
    issue..
    Or let me know how you create a .xjs file.
    Any idea what is the main file class in
    jaxb-rt-1.0-ea.jar that creates a xjs file ?
    All/any help appreciated. Thanks in advance.

  • Encoding problem in JAXB

    Hi ;
    When unmarshaling XML which it's encoding is "ISO-8859-9" ,
    i couldn't get the right encoded String objects .
    for example my XML starting like that :
    <?xml version="1.0" encoding="ISO-8859-9" ?><VIEW>
    <TYPE>INSERT</TYPE>
    <TableDefinition>
    <TableName>LK_TRADERLAR</TableName>
    <Column ColumnName='B�LG�' id='1' />
    <Column ColumnName='ADSOYAD����' id='2' />
    When i try to get ColumnName's data, it seems like that
    B?LG?
    ADSOYAD????
    How can set JAXB to the right encoding ??
    Regards
    Altug.

    Hi,
    start your xml file like
    <?xml version="1.0" encoding="windows-1254"?>
    // ("windows-1254" is for Turkish, I think you are Turk too. I wanted to write in Turkish but maybe somebody might inform as abuse)
    I can solve this problem like this on a MS Windows OS.
    My problem is marshalling. I cant set encoding with marshalling. It always start to write UTF-8 encoding.I dont want to change the produced classes before asking this forum. the last change is changing produced classes.
    AhmetAkk�k

  • Problem with JAXB

    I am trying to run a simple test program to unmarshall and XML doc and am getting the following error:
    [erdos OpenOfficeDev]$ ./java_jaxb.sh unmarshall sampleDoc.xml
    JAXBLIB /opt/tomcat50-jwsdp/jaxb/lib
    CLASSPATH /opt/tomcat50-jwsdp/jaxb/lib/jaxb-api.jar:/opt/tomcat50-jwsdp/jaxb/lib/jaxb-impl.jar:/opt/tomcat50-jwsdp/jaxb/lib/jaxb-libs.jar:/opt/tomcat50-jwsdp/jaxb/lib/jaxb-xjc.jar:/usr/java/j2sdk1.4.2_08/jre/lib/ext/xml-apis.jar:.:/opt/tomcat50-jwsdp/jwsdp-shared/lib/jax-qname.jar:/opt/tomcat50-jwsdp/jwsdp-shared/lib/namespace.jar:/opt/tomcat50-jwsdp/jwsdp-shared/lib/relaxngDatatype.jar:/opt/tomcat50-jwsdp/jaxp/lib/endorsed/dom.jar:/opt/tomcat50-jwsdp/jaxp/lib/endorsed/sax.jar:/opt/tomcat50-jwsdp/jaxp/lib/endorsed/xalan.jar:/opt/tomcat50-jwsdp/jaxp/lib/endorsed/xercesImpl.jar:/home/nscharfe/netbeans-4.1/ide5/modules/autoload/ext/xerces-2.6.2.jar:/home/nscharfe/resolver.jar:/home/nscharfe/xercesImpl.jar:/home/nscharfe/xercesSamples.jar:/home/nscharfe/xml-apis.jar:/opt/tomcat50-jwsdp/jaxp//jaxp-api.jar
    args.length =1
    unmarshall.Main file=sampleDoc.xml
    JAXBContext
    jc ood_jaxb.impl.runtime.DefaultJAXBContextImpl@d2906a
    u ood_jaxb.impl.runtime.UnmarshallerImpl@1434234
    Exception in thread "main" java.lang.NoSuchMethodError: javax.xml.parsers.SAXParserFactory.getSchema()Ljavax/xml/validation/Schema;
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.<init>(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.getXMLReader(AbstractUnmarshallerImpl.java:80)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178)
    at unmarshall.main(unmarshall.java:56)
    Any ideas what the problem is? Do I need to include anything else in my classpath?
    I am running redhat linux.
    Any help is GREATLY appreciated

    Since I am running java 1.5.x, it seems like the only solution that the above thread suggests is to add rt.jar to my classpath. I did that and it did not help so my path is now;
    CLASSPATH /opt/tomcat50-jwsdp/jaxb/lib/jaxb-api.jar:/opt/tomcat50-jwsdp/jaxb/lib/jaxb-impl.jar:
    /opt/tomcat50-jwsdp/jaxb/lib/jaxb-libs.jar:/opt/tomcat50-jwsdp/jaxb/lib/jaxb-xjc.jar:
    /usr/java/j2sdk1.4.2_08/jre/lib/ext/xml-apis.jar:.:/opt/tomcat50-jwsdp/jwsdp-shared/lib/jax-qname.jar:
    opt/tomcat50-jwsdp/jwsdp-shared/lib/namespace.jar:/opt/tomcat50-jwsdp/jwsdp-shared/lib/relaxngDatatype.jar:
    /home/nscharfe/jdk1.5.0_04/jre/lib/rt.jar:/home/nscharfe/jdk1.5.0_04/jre/lib/javaws.jar:/home/nscharfe/jdk1.5.0_04/jre/lib/jce.jar:
    /home/nscharfe/jdk1.5.0_04/jre/lib/jsse.jar:/home/nscharfe/jdk1.5.0_04/jre/lib/plugin.jar:
    /home/nscharfe/jdk1.5.0_04/jre/lib/deploy.jar:/home/nscharfe/jdk1.5.0_04/jre/lib/charsets.jar:
    /opt/tomcat50-jwsdp/jaxp/lib/endorsed/dom.jar:/opt/tomcat50-jwsdp/jaxp/lib/endorsed/sax.jar:
    /opt/tomcat50-jwsdp/jaxp/lib/endorsed/xalan.jar:/opt/tomcat50-jwsdp/jaxp/lib/endorsed/xercesImpl.jar:
    /home/nscharfe/netbeans-4.1/ide5/modules/autoload/ext/xerces-2.6.2.jar:/home/nscharfe/resolver.jar:
    /home/nscharfe/xercesImpl.jar:/home/nscharfe/xercesSamples.jar:/home/nscharfe/xml-apis.jar:
    /opt/tomcat50-jwsdp/jaxp//jaxp-api.jar
    Did I miss any important info on the above thread? Any other suggestions?
    thanks so much for the help.

  • Problem with JAXB Unmarshaller

    This exception ocurred in production environment. Notice that always it happens in SAXUnmarshallerHandlerImpl.getCurrentHandler method but not always in the same package and sometimes it occurs and sometimes doesn�t. In test environment it never happens. Could it be a memory problem? I write some examples:
    java.lang.ArrayIndexOutOfBoundsException: -1
    at es.indra.bizlogic.jaxb.air.output.impl.runtime.SAXUnmarshallerHandlerImpl.getCurrentHandler(Unknown Source)
    at es.indra.bizlogic.jaxb.air.output.impl.runtime.SAXUnmarshallerHandlerImpl.endElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    java.lang.ArrayIndexOutOfBoundsException: -1
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.getCurrentHandler(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.popContentHandler(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.AbstractUnmarshallingEventHandlerImpl.revertToParentFromEnterElement(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.EDATEImpl$Unmarshaller.enterElement(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.startElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    java.lang.ArrayIndexOutOfBoundsException: -1
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.getCurrentHandler(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.endElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    java.lang.ArrayIndexOutOfBoundsException: -1
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.getCurrentHandler(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.popContentHandler(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.AbstractUnmarshallingEventHandlerImpl.revertToParentFromEnterElement(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.CODEImpl$Unmarshaller.enterElement(Unknown Source)
    at es.indra.bizlogic.jaxb.fare.output.impl.runtime.SAXUnmarshallerHandlerImpl.startElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    Message was edited by:
    Ana_Indra_Madrid

    I had the same problem! The answer is to include '.' in your CLASSPATH. A dot like this means the current directory. The compiler won't find all the package files in the current directory unless its path is explicitly set in CLASSPATH. Seems strange as you might expect a compiler at least to try looking for files wherever you currently are, but it's not the case. So, my CLASSPATH declaration is as follows, starting with '.;' and then continuing with all the required jar files:
    .;c:\jwsdp-1.3\jaxb\lib\jaxb-api.jar;c:\jwsdp-1.3\jaxb\lib\jaxb-xjc.jar;c:\jwsdp-1.3\jaxb\lib\jaxb-impl.jar;c:\jwsdp-1.3\jaxb\lib\jaxb-libs.jar;c:\jwsdp-1.3\jaxp\lib\jaxp-api.jar;c:\jwsdp-1.3\jaxp\lib\endorsed\sax.jar;c:\jwsdp-1.3\jaxp\lib\endorsed\dom.jar;c:\jwsdp-1.3\jaxp\lib\endorsed\xercesImpl.jar;c:\jwsdp-1.3\jaxp\lib\endorsed\xalan.jar;c:\jwsdp-1.3\jwsdp-shared\lib\jax-qname.jar;c:\jwsdp-1.3\jwsdp-shared\lib\namespace.jar;c:\jwsdp-1.3\jwsdp-shared\lib\xsdlib.jar;c:\jwsdp-1.3\jwsdp-shared\lib\relaxngDatatype.jar

  • Problem with JAXB context.createUnmarshaller();

    hi,
    I'm running into problems when trying to use JAXB context.createUnmarshaller();
    so far I have:
    1. extracted an xsd from my XML
    2. Added the following 4 jars to my project: jaxb-api,jaxb-xjc,jaxb-impl,jaxb1-impl
    3. used xjc and successfully generate the source for my custom classes
    4. compiled my custom classes and added them to my project's build path.
    I have the following code:
    //this line works and I can see the context being generated with my custom classes
    JAXBContext context = JAXBContext.newInstance("path.to.my.jaxb.bo's");
    //the following line returns an error
    Unmarshaller unmarshaller = context.createUnmarshaller();
    the error I get is:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
         at com.sun.xml.bind.v2.runtime.JAXBContextImpl.createUnmarshaller(JAXBContextImpl.java:604)
         at com.sun.xml.bind.v2.runtime.JAXBContextImpl.createUnmarshaller(JAXBContextImpl.java:107)
         at com.cyclicom.sem.ApiDao.SEMApiReader.readApi(SEMApiReader.java:46)
         at com.cyclicom.sem.SEMDataWriter.init(SEMDataWriter.java:26)
         at com.cyclicom.sem.SEMDataWriter.main(SEMDataWriter.java:19)

    ok, I just found the problem myself seems like a bunch of jars were missing, if your reading this and ran into the same problem make sure you have the following libs in your build path, on top of JAXB lib:
    sjsxp
    jwsdp-shared
    both are a part of the jwsdp

  • Problem with JAXB Unmarshall - javax.xml.bind.UnmarshalException

    Hi,
    I'm getting an expection while unmarshalling using JAXB. The error is as follows :
    DefaultValidationEventHandler: [ERROR]: unexpected element (uri:"http://www.etrade.com/ee/systemdomainao/search", local:"Context_Id"). Expected elements are <{}contextId>,<{}predicateInterceptor>,<{}isDefaultsearch>,<{}implicitContextSQL>,<{}contextName>,<{}searchId>,<{}implicitContextText>
    I've generated JAXB classes using xjc command from my schema. The root element is Search object which has a List of Searchcontext and Columlist object. When I'm trying to unmarshall the XML, I'm getting the above exception. What is baffling, if I comment out the <tns:SearchContext> entry from the XML, unmarshall doesn't throw any exception and populates the columnlist properly. Columnlist and Searchcontext have little difference except that columnlist contains more elements.
    Here'e the unmarshall code,
    URL metadataURL = this.getClass().getClassLoader().getResource("metadata/search/PARTICIPANT.xml");
    JAXBContext jc = JAXBContext.newInstance("com.etrade.ee.systemdomainao.search.domain");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
    Search search = (Search)unmarshaller.unmarshal(metadataURL);
    Any pointers will be highly appreciated.
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    XSD :
    XSD :
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.etrade.com/ee/systemdomainao/search" targetNamespace="http://www.etrade.com/ee/systemdomainao/search" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <!-- Searchcontext type definition -->
         <xs:complexType name="Searchcontext">
              <xs:sequence>
                   <xs:element name="Context_Id" type="xs:int"/>
                   <xs:element name="Search_Id" type="xs:string"/>
                   <xs:element name="Context_Name" type="xs:string"/>
                   <xs:element name="Implicit_Context_SQL" nillable="true">
                        <xs:simpleType>
                             <xs:restriction base="xs:string">
                                  <xs:maxLength value="500"/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>
                   <xs:element name="Implicit_Context_Text" nillable="true">
                        <xs:simpleType>
                             <xs:restriction base="xs:string">
                                  <xs:maxLength value="500"/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>
                   <xs:element name="Is_Defaultsearch" type="xs:boolean" nillable="true"/>
                   <xs:element name="Predicate_Interceptor" type="xs:string" nillable="true"/>
              </xs:sequence>
         </xs:complexType>
         <!-- Searchlist type definition -->
         <xs:complexType name="Columnlist">
              <xs:sequence>
                   <xs:element name="Columnlist_Id" type="xs:int"/>
                   <xs:element name="Search_Id" type="xs:string"/>
                   <xs:element name="Is_Quicksearchable" type="xs:boolean" nillable="true"/>
                   <xs:element name="Is_Advancesearchable" type="xs:boolean" nillable="true"/>
                   <xs:element name="Is_Quicksearchview" type="xs:boolean" nillable="true"/>
                   <xs:element name="Is_Fullview" type="xs:boolean" nillable="true"/>
                   <xs:element name="Is_Sortable" type="xs:boolean" nillable="true"/>
                   <xs:element name="Is_Defaultsort" type="xs:boolean" nillable="true"/>
                   <xs:element name="Default_SortOrder" type="xs:string" nillable="true" minOccurs="0"/>
                   <xs:element name="Display_Order" type="xs:int" nillable="true"/>               
                   <xs:element name="Default_Value" type="xs:string" nillable="true" maxOccurs="6"/>
                   <xs:element name="Default_Operator" type="xs:string" nillable="true"/>
                   <xs:element name="Is_Closedset" type="xs:boolean"/>
                   <xs:element name="Closedset_List_Name" type="xs:string" nillable="true"/>
                   <xs:element name="Is_RelatedMenu" type="xs:boolean" minOccurs="0"/>
                   <xs:element name="Column_Name" type="xs:string"/>
                   <xs:element name="Display_Name" type="xs:string"/>
                   <xs:element name="Is_UDF" type="xs:boolean" nillable="true"/>
                   <xs:element name="Table_Name" type="xs:string"/>
                   <xs:element name="Data_Type" type="xs:string"/>
                   <xs:element name="Column_Size" type="xs:int"/>
              </xs:sequence>
         </xs:complexType>
         <!-- Search declaration -->
         <xs:element name="Search">
              <!--<choice>
         <xs:interface name="java.io.Serializable" />
         </choice>-->
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="Search_Id" type="xs:string"/>
                        <xs:element name="Schema_Set">
                             <xs:simpleType>
                                  <xs:restriction base="xs:string">
                                       <xs:maxLength value="20"/>
                                       <xs:minLength value="1"/>
                                  </xs:restriction>
                             </xs:simpleType>
                        </xs:element>
                        <xs:element name="SearchContext" type="tns:Searchcontext" maxOccurs="unbounded"/>
                        <xs:element name="ColumnList" type="tns:Columnlist" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
              <xs:key name="Search_PrimaryKey_1">
                   <xs:selector xpath="."/>
                   <xs:field xpath="tns:Search_Id"/>
              </xs:key>
              <xs:keyref name="Searchcontext_ForeignKey_1" refer="tns:Search_PrimaryKey_1">
                   <xs:selector xpath=".//tns:SearchContext"/>
                   <xs:field xpath="tns:Search_Id"/>
              </xs:keyref>
              <xs:keyref name="Columnlist_ForeignKey_2" refer="tns:Search_PrimaryKey_1">
                   <xs:selector xpath=".//tns:ColumnList"/>
                   <xs:field xpath="tns:Search_Id"/>
              </xs:keyref>
              <xs:key name="Searchcontext_PrimaryKey_1">
                   <xs:selector xpath=".//tns:SearchContext"/>
                   <xs:field xpath="tns:Context_Id"/>
              </xs:key>
              <xs:key name="Columnlist_PrimaryKey_1">
                   <xs:selector xpath=".//tns:ColumnList"/>
                   <xs:field xpath="tns:Columnlist_Id"/>
              </xs:key>
         </xs:element>
    </xs:schema>

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

  • Problem running JAXB sample applications

    hi,
    I have been trying to run the JAXB sample applications provided with JWSDP1.1
    Class Paths etc are set as follows as specified :
    set JAVA_HOME=C:\Program Files\jdk1.3.1_03
    set JWSDP_HOME=C:\Program Files\jwsdp-1.1
    set JAXB_HOME=%JWSDP_HOME%\jaxb-1.0
    set JAXB_LIBS=%JAXB_HOME%\lib
    set JAXP_LIBS=%JWSDP_HOME%\jaxp-1.2.2\lib
    set JWSDP_LIBS=%JWSDP_HOME%\jwsdp-shared\lib
    set PATH=%JAXB_HOME%\bin;%JWSDP_HOME%\jwsdp-shared\bin;%PATH%
    set CLASSPATH=%JAXB_LIBS%\jaxb-api.jar;%JAXB_LIBS%\jaxb-ri.jar;%JAXB_LIBS%\jaxb-xjc.jar;%JAXB_LIBS%\jaxb-libs.jar;%JAXP_LIBS%\jaxb-api.jar;%JAXP_LIBS%\endorsed\xercesImpl.jar;%JAXP_LIBS%\endorsed\xalan.jar;%JAXP_LIBS%\endorsed\sax.jar;%JAXP_LIBS%\endorsed\dom.jar;%JWSDP_LIBS%\jax-qname.jar;%JWSDP_LIBS%namespace.jar;.
    cd %JAXB_HOME%\examples\users-guide\SampleApp1
    xjc.bat po.xsd -p primer.po
    javac Main.java primer\po\*.java primer\po\impl\*.java
    I keep running into the following error message at this stage :
    cannot access javax.xml.transform.Source
    file javax\xml\transform\Source.class not found
    (PurchaseOrder)u.unmarshal(new FileInputStream("po.xml"));
    Help greatly appreciated!! Thanks

    well, i think i don't see the jaxp-api.jar in you classpath.
    (javax.xml.transform.Source is in this jar)
    you did put the jaxb-api.jar in the classpath but this is not the same one (obviously!)

  • Problem in JAXB

    Hi.
    Can we have an XSD file with only some tag elements from the XML file. I am having an XML file of around 250+ (distinct)tag elements. Can we have a XSD file with few elements entered and some extra tags present in XML file.

    Thanks for the reply,
    Yes I tried the any element option. But i was able to use xs:any for only 1 element. We are not able to use the xs:any more than once.
    Or i have to specify the tag name and give the type as any. But in this case i will be mentioning the tag name which i dont want to.

  • Help: problems with JAXB unmarshalling

    Hi all,
    I've got a DOM Document object, which I wish to unmarshall. It all works great, but I wish to do some better validation handling, and this is where I see something weird: whenever a ValidationEvent comes into my custom ValidationEventHandler, it practically contains no info on the location of the event. This is the typical content of event.getLocator():
    columnNumber = -1
    lineNumber = -1
    node = null
    object = null
    offset = -1
    url = null
    This is the code:
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputStream is = new FileInputStream("d:/temp/file1.xml");
        Document doc = builder.parse(is);
        is.close();
        JAXBContext jaxbContext = JAXBContext
                  .newInstance("com.company.xml");
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setEventHandler(new MyValidator(unmarshaller
                  .getEventHandler()));
        Object result = unmarshaller.unmarshal(doc.getDocumentElement());thanks

    Found a solution. I added:
    unmarshaller.setValidating(true);
    I also had to make sure that the xml file did not contain schema info (i.e. shcemaLocation, etc), otherwise, I get a NullPointerException - I don't yet know why, but it's good enough for me at the moment :-)
    Now, the ValidationEventLocator contains a ref to the Node in my DOM.

  • JAXB: Problem generating java enums

    Hi
    I'm having som problems configuring JAXB to generate type safe enums. The schema I'm using has several structures similar to this simplified example:
        <xs:element name="Car">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="CarTypeEnumInComplexType">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="Truck"/>
                                <xs:enumeration value="Jeep"/>
                                <xs:enumeration value="SUV"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>In the resulting Java code CarTypeEnumInComplexType is just generated as a String value in the Car Interface.
    What I really want is a separate Java class for "CarTypeEnumInComplexType" - with constants for each enumeration value.
    However, I do not want to change the schema - as this is maintained by another company.
    For a moment I thought I'd found the solution: By setting the global binding setting "typesafeEnumBase" to "xs:string" I made JAXB generate this kind of enumeration classes in cases like this:
    <xs:simpleType name="CarTypeEnum">
            <xs:restriction base="xs:string">
                <xs:enumeration value="Truck"/>
                <xs:enumeration value="Jeep"/>
                <xs:enumeration value="SUV"/>
            </xs:restriction>
        </xs:simpleType>However, I still can't make this work for enumerations nested within a complex type as illustrated in the first example.
    I'm new to XML schemas and JAXB - so I may be missing something obvious here...
    Is there any way to make JAXB generate an enum class for "CarTypeEnumInComplexType" in my first example without altering the schema structure?
    Vidar

    Well I couldnt really find any clear documentation to this , however with this post I was able to get going in the right direction I thought I would post the solution here.
    This assumes you have some control of your schema , it doesnt solve the problem where you cant touch the schema at all.
    So first my bindings.xjb file looks like:
    <?xml version="1.0"?>
    <jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jxb:extensionBindingPrefixes="xjc">
         <jxb:bindings schemaLocation="CMSOSS.xsd" node="/xs:schema">
              <jxb:globalBindings typesafeEnumBase ="xs:string">
                   <xjc:serializable uid="12343"/>
              </jxb:globalBindings>
              <jxb:schemaBindings>
                   <jxb:package name="com.cms.oss"/>
                   <jxb:nameXmlTransform>
                        <jxb:elementName suffix="Element"/>
                   </jxb:nameXmlTransform>
              </jxb:schemaBindings>
         </jxb:bindings>
    </jxb:bindings>
    First its necessary to have the enum type defined outside of the complex type:
    <xs:simpleType name="serviceTypeEnum">
              <xs:annotation>
                   <xs:documentation>Type of service being added (RES, BUS, FAX, POTS)</xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:string">
                   <xs:enumeration value="RES"/>
                   <xs:enumeration value="BUS"/>
                   <xs:enumeration value="FAX"/>
                   <xs:enumeration value="POTS"/>
              </xs:restriction>
         </xs:simpleType>
    Then you can use the enum in your complex type in the following manner
         <xs:element name="service">
              <xs:annotation>
                   <xs:documentation>Create a service tag for each new line of service</xs:documentation>
              </xs:annotation>
              <xs:complexType>
                   <xs:sequence>
                        <xs:element ref="phone"/>
                        <xs:element name="type" type="serviceTypeEnum">
                             <xs:annotation>
                                  <xs:documentation>Type of service being added (RES, BUS, FAX, POTS)
                                  </xs:documentation>
                             </xs:annotation>
                        </xs:element>
                        <xs:element ref="lineDevice"/>
                        <xs:element ref="LNP" minOccurs="0"/>
                        <xs:element ref="VMPIN"/>
                        <xs:element ref="location"/>
                        <xs:element name="userService" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
    Some better documentation on this would sure help ... however I dont think this solves completely the original problem...
    I would think that type safe enums should be built into the specification without all this custom binding stuff.
    R
    S

  • JAXB unmarshalling elements with xs:type explicitly set

    I am working with XML content where the XSD defines an element as being of a complexType (say "ParentType") but the content explicitly sets the element's xs:type attribute to an extension of that complexType (say "ChildType").
    As far as I can tell the XML is valid, but JAXB issues the following when unmarshalling:
    DefaultValidationEventHandler: [ERROR]: Unexpected element {}:child1
    javax.xml.bind.UnmarshalException: Unexpected element {}:child1
    Where <child1> is added via the extension.
    Is this a problem with JAXB or my XSD?
    (XSD and XML enclosed below)
    XSD ------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:complexType name="ParentType">
    <xs:sequence>
    <xs:element name="parent1" type="xs:string"/>
    <xs:element name="parent2" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ChildType">
    <xs:complexContent>
    <xs:extension base="ParentType">
    <xs:sequence>
    <xs:element name="child1" type="xs:string"/>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="child" type="ParentType"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    XML -----------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="problem.xsd">
    <child xsi:type="ChildType">
    <parent1/>
    <parent2/>
    <child1/>
    </child>
    </root>

    JAXB doesn't handle OO schema design. I tried to do something similar where I defined a type called base and then defined that my document contained 1 or more base elements. Then I tried to unmarshall a document that contained elements that were of types extending from base. I ended up with the same issue.
    It seems that when the xjc compiler defines the classes it isn't smart enough to realize the element defined as parent could also contain a child element since child extends parent. Your XSD and XML are valid.
    I would think that JAXB should identify that because there is a type the extends the defined type, that an element of the sub-type might be subsituted i.e. check the actual type of the element in the XML before attempting to unmarshall it as the default type. It doesn't do that. I am not sure if this is as desinged, or a flaw in the implementation.

Maybe you are looking for