Jaxb unmarshalling and setvalidating()

I am using jaxb 1.0 with jdk1.4 , i am trying to unmarshall the incoming request which a xml.
It has a element called attachment list which is mandatory as per the schema. but i dont want my unmarshaller to validate request and throw error instead i just need to objects from unmarshaller. so i set the setvalidating(false).but i am still getting the validation error.Any help in this is highly appreciated.

Check the date of the post dude - its months old and the dude who posted it hasn't been back since then (only one post, this one). If you want to help, focus on recent threads. Resurrecting old threads triggers other helpful people to unnecessarily invest time into them and creates extra work for the moderators.

Similar Messages

  • JAXB Unmarshalling and namespace

    Hi All ,
    Im using jaxb to marshall and unmarshall xml messages.Every thing seems to work fine expect for one
    small part ...... the namespace is removed form the xml .For example
    <RECORD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Record.xsd">
    becomes
    <RECORD>
    Any idea why this happens ?
    thanks
    Jim

    Hi Jimmy -
    Have you tried including this code at marshall time?
    marshaller.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, "schema_path path_to_xsd.xsd");
    Good luck.
    cm

  • JAXB Unmarshalling complexity

    Hello all,
    I need help on JAXB
    the situation is as below...
    i have to write a program that communicates with a server. the communication is request-response kind of communication which is to be carried out through XML.
    so everytime i have to send any request i need to create an XML and then send it to the server. i get the response in the form of XML. then i have to parse the XML to find out whats the response.
    previously i used DOM and SAX for creating XML and parsing XML respectively.
    now every response i get, i have to validate it against a DTD.
    now i'm trying out JAXB. so i first converted all the DTDs to XSD (xml schema docs). because JAXB doesn't support DTDs.
    now with JAXB, i'm creating the XML requests and sending it to the server and getting the response.
    but here is one problem.....
    as with JAXB, of i have to unmarshall the xml response i have to first create a JAXB context. and unmarshall it to that xml object that i'm expecting. but suppose i get some other response then how am i supposed to know that.
    i'll explain the above with a small example.
    suppose i have the following DTDs
    SearchRequest.dtd..............for search requests
    SearchResponse.dtd..............for search responses
    ErrorResponse.dtd.............for if the server sends any error.
    now first i convert this DTDs to XSDs and so i get
    SearchRequest.xsd, SearchResponse.xsd, ErrorResponse.xsd
    and then using the JAXB compiler i create the JAXB derived classes in the following package
    com.xyz.SearchRequest
    com.xyz.SearchResponse
    com.xyz.ErrorResponse
    now suppose i created the xml request and sent it to the server and i got the response. and i have to unmarshall it.
    (the server will send me SearchResponse.xml if everything if fine but ErrorResponse.xml it theres an error).
    now heres the problem. the server will send the SearchResponse or ErrorResponse. and ill have to determine what it is before i start to unmarshall.
    i hope i have communicated my problem....
    thankyou
    java-jones

    Not sure if this will help you or if this is what you are looking for, but from the JAXB Users' Guide:
    More About Unmarshalling
    The Unmarshaller class in the javax.xml.bind package provides the client application the ability to convert XML data into a tree of Java content objects. The unmarshal method for a schema (within a namespace) allows for any global XML element declared in the schema to be unmarshalled as the root of an instance document. The JAXBContext object allows the merging of global elements across a set of schemas (listed in the contextPath). Since each schema in the schema set can belong to distinct namespaces, the unification of schemas to an unmarshalling context should be namespace-independent. This means that a client application is able to unmarshal XML documents that are instances of any of the schemas listed in the contextPath; for example:
    JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
    Unmarshaller u = jc.createUnmarshaller();
    FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
    BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
    BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error

  • JAXB unmarshalling error

    We are getting a JAXB unmarshalling error:
    while processing the following <condition> tag which is of type xsd:string
    <condition> x < 100 </condition>
    The error is probably happening due to "<" token as a part of string type.
    xml.bind.JAXBException: Unexpected error in Unmarshalling
    at oracle.xml.jaxb.JaxbUnmarshaller.unmarshal(JaxbUnmarshaller.java:224)
    Any ideas how to resolve this issue?
    Note
    <condition> x >100 </condition> is getting unmarshalled successfully by JAXB unmarshaller.
    Thanks

    Hi,
    Did you tried to put & lt; (without space) instead of < ?
    Best Regards,
    Paweł

  • JAXB unmarshalling error for " " token as part of xsd:string type element

    JAXB unmarshalling error for "<" token as part of xsd:string type element
    We are getting a JAXB unmarshalling error:
    while processing the following <condition> tag which is of type xsd:string
    <condition> x < 100 </condition>
    The error is probably happening due to "<" token as a part of string type.
    xml.bind.JAXBException: Unexpected error in Unmarshalling
    at oracle.xml.jaxb.JaxbUnmarshaller.unmarshal(JaxbUnmarshaller.java:224)
    Any ideas how to resolve this issue?
    Note
    <condition> x > 100 </condition> is getting unmarshalled successfully by JAXB unmarshaller.
    Thanks

    Hi,
    Did you tried to put & lt; (without space) instead of < ?
    Best Regards,
    Paweł

  • JAXB cannot unmarshall and previous posts do not seem to be related

    Hello,
    Recently, we had to change some of our XSDs, so I went and downloaded the latest Java web services pack (v1.6) and made the changes to the schema (only one new element). First, I realized we were using a 0.75 EA1 release of JAXB and that I would have to re-generate all the classes for all our current XSDs because of 0.75 is so outdated.
    I regenerated all the classes and everything seemed to be in good order. When I started my application I received the following error (this is in jdk 1.5)
    Now, the XSD and the XML have not changed in 3 years... why is it that using this new version of JAXB seems to have messed things up? This errors is received when trying to unmarshall. I have been looking at this for three days and reading all the posts, i don;t think this is a namespaces issue because it used to work.... i just don't get it. any help is GREATLY appreciated.
    Thanks
    JAVA CODE HERE ********************************************
    JAXBContext jc = com.sun.xml.bind.ContextFactory.createContext("com.testbed.common.config", new JAXBClassLoader());
    Unmarshaller u = jc.createUnmarshaller();
    EXCEPTION HERE *********************************
    ./shorg.xml.sax.SAXParseException: unexpected root element ConfigInfo
    at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:94)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:127)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:136)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:145)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:163)
    Here is the XML for the config file -
    XML HERE *************************************************
    <ConfigInfo>
    <LogFileConfig>logging.cfg</LogFileConfig>
    <HeartbeatTimeout>0</HeartbeatTimeout>
    <HeartbeatTopic>testTopic</HeartbeatTopic>
    <DatabaseConfig>
    <Name>TEST</Name>
    <Info>timmy/[email protected]:1521:DB1</Info>
    </DatabaseConfig>
    <JMSConfig>
    <MyName>TESTjms</MyName>
    <Connections>
    <connection id="1">
    <Address>192.168.1.2</Address>
    <Port>3035</Port>
    <Type>tcp</Type>
    <Factory>org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory</Factory>
    </connection>
    </Connections>
    </JMSConfig>
    <AgentProcessor>
    <MappingFile>test.map</MappingFile>
    <CommandFile>test.com</CommandFile>
    <EventQueueTime>15000</EventQueueTime>
    <SuppressionFile>supress.sup</SuppressionFile>
    </AgentProcessor>
    <StatusAlertTime>15000</StatusAlertTime>
    </ConfigInfo>
    And here is the XSD
    XSD HERE ***************************************************
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <xsd:annotation>
              <xsd:documentation xml:lang="en">Configuration file formats</xsd:documentation>
         </xsd:annotation>
         <xsd:element name="ConfigInfo" type="configInfoType">
              <xsd:annotation>
                   <xsd:documentation>The root element of the configuration file</xsd:documentation>
              </xsd:annotation>
         </xsd:element>
         <xsd:complexType name="configInfoType">
              <xsd:annotation>
                   <xsd:documentation>Contains the elements of a configuration file</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="LogFileConfig" type="xsd:string"/>
                   <xsd:element name="HeartbeatTimeout" type="xsd:int"/>
                   <xsd:element name="HeartbeatTopic" type="xsd:string"/>
                   <xsd:element name="DatabaseConfig" type="dbConfigType" minOccurs="0" maxOccurs="unbounded"/>
                   <xsd:element name="JMSConfig" type="jmsConfigType" minOccurs="0"/>
                   <xsd:element name="NetsaintConfig" type="netsaintConfigType" minOccurs="0"/>
                   <xsd:element name="EventProcessor" type="epConfigType" minOccurs="0"/>
                   <xsd:element name="AgentProcessor" type="agConfigType" minOccurs="0"/>
                   <xsd:element name="DatabaseAgent" type="dbAgentType" minOccurs="0"/>
                   <xsd:element name="Heartbeater" type="hbConfigType" minOccurs="0"/>
                   <xsd:element name="StatusAlertTime" type="xsd:long"/>
                   <xsd:element name="RemoteConnection" type="remoteConnConfig" minOccurs="0"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="dbConfigType">
              <xsd:annotation>
                   <xsd:documentation>The Database configuration element, with a database name and connection info</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="Name" type="dbInstanceType"/>
                   <xsd:element name="Info" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:simpleType name="dbInstanceType">
              <xsd:annotation>
                   <xsd:documentation>Limits the database connections</xsd:documentation>
              </xsd:annotation>
              <xsd:restriction base="xsd:string">
                   <xsd:pattern value="TEST|TEST2"/>
              </xsd:restriction>
         </xsd:simpleType>
         <xsd:complexType name="jmsConfigType">
              <xsd:annotation>
                   <xsd:documentation>The base of the JMS configurations</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="MyName" type="xsd:string"/>
                   <xsd:element name="Connections" type="connType"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="connType">
              <xsd:annotation>
                   <xsd:documentation>An individual JMS configuration with a priority ranked id and associated connection information</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="connection" maxOccurs="unbounded">
                        <xsd:annotation>
                             <xsd:documentation>id attribute</xsd:documentation>
                        </xsd:annotation>
                        <xsd:complexType>
                             <xsd:sequence>
                                  <xsd:element name="Address" type="xsd:string"/>
                                  <xsd:element name="Port" type="xsd:int"/>
                                  <xsd:element name="Type" type="xsd:string"/>
                                  <xsd:element name="Factory" type="xsd:string"/>
                             </xsd:sequence>
                             <xsd:attribute name="id" type="xsd:int" use="required"/>
                        </xsd:complexType>
                   </xsd:element>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="netsaintConfigType">
              <xsd:annotation>
                   <xsd:documentation>Connection info for NetSaint alerting</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="Address" type="xsd:string"/>
                   <xsd:element name="Port" type="xsd:int"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="epConfigType">
              <xsd:annotation>
                   <xsd:documentation>Event Processor base configuration</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="TimeoutWarning" type="xsd:int"/>
                   <xsd:element name="TimeoutError" type="xsd:int"/>
                   <xsd:element name="Adaptors" type="adapType"/>
                   <xsd:element name="SuppressionTimeout" type="xsd:int" default="3600000"/>
                   <xsd:element name="EmailTimeoutWarning" type="xsd:int" minOccurs="0"/>
                   <xsd:element name="EmailTimeoutError" type="xsd:int" minOccurs="0"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="adapType">
              <xsd:annotation>
                   <xsd:documentation>The definition of the available adaptors</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="EmailAdaptor" type="emailType" minOccurs="0"/>
                   <xsd:element name="DBAdaptor" type="dbType" minOccurs="0"/>
                   <xsd:element name="FrontEndAdaptor" type="feType" minOccurs="0"/>
                   <xsd:element name="MetricsAdaptor" type="metricsType" minOccurs="0"/>
                   <xsd:element name="NetsaintAdaptor" type="netsaintType" minOccurs="0"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="netsaintType">
              <xsd:sequence>
                   <xsd:element name="Enabled" type="YesNo"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="emailType">
              <xsd:annotation>
                   <xsd:documentation>Email adaptor definition</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="SMTPHost" type="xsd:string"/>
                   <xsd:element name="Sender" type="xsd:string"/>
                   <xsd:element name="Recipient" type="xsd:string" minOccurs="0"/>
                   <xsd:element name="GPGCommand" type="xsd:string" minOccurs="0"/>
                   <xsd:element name="LookupEmails" type="YesNo" minOccurs="0"/>
                   <xsd:element name="XSL" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:simpleType name="YesNo">
              <xsd:annotation>
                   <xsd:documentation>A "Y" or "N" type for use within the configuration file</xsd:documentation>
              </xsd:annotation>
              <xsd:restriction base="xsd:string">
                   <xsd:pattern value="Y|N"/>
              </xsd:restriction>
         </xsd:simpleType>
         <xsd:complexType name="dbType">
              <xsd:annotation>
                   <xsd:documentation>Database adaptor configuration</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="Threads" type="xsd:int"/>
                   <xsd:element name="XSL" type="xsd:string" minOccurs="0"/>
                   <xsd:element name="Mode" type="dbProcessingMode"/>
                   <xsd:element name="DeviceServerAddr" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:simpleType name="dbProcessingMode">
              <xsd:annotation>
                   <xsd:documentation>Defines the available Database Adaptor modes</xsd:documentation>
              </xsd:annotation>
              <xsd:restriction base="xsd:string">
                   <xsd:pattern value="NORMAL|XML"/>
              </xsd:restriction>
         </xsd:simpleType>
         <xsd:complexType name="feType">
              <xsd:annotation>
                   <xsd:documentation>FrontEnd adaptor definition</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="Publish" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="metricsType">
              <xsd:annotation>
                   <xsd:documentation>Metrics adaptor definition</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="Path" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="agConfigType">
              <xsd:annotation>
                   <xsd:documentation>AgentPeer configuration</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="MappingFile" type="xsd:string"/>
                   <xsd:element name="CommandFile" type="xsd:string"/>
                   <xsd:element name="EventQueueTime" type="xsd:int"/>
                   <xsd:element name="SuppressionFile" type="xsd:string" minOccurs="0"/>
                   <xsd:element name="FWHourlyCommand" type="xsd:string" minOccurs="0"/>
                   <xsd:element name="FWDailyCommand" type="xsd:string" minOccurs="0"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="dbAgentType">
              <xsd:annotation>
                   <xsd:documentation>Database Agent configuration</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="LowLevelAckTime" type="xsd:int"/>
                   <xsd:element name="LowLevelQueryWindow" type="xsd:int"/>
                   <xsd:element name="MessageQueryTime" type="xsd:int"/>
                   <xsd:element name="MaxMessagingRate" type="xsd:double"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="hbConfigType">
              <xsd:annotation>
                   <xsd:documentation>Heartbeater configuration</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="HeartbeatTopic" type="xsd:string"/>
                   <xsd:element name="HeartbeatPeriod" type="xsd:int"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="remoteConnConfig">
              <xsd:annotation>
                   <xsd:documentation>Remote Connection configuration info</xsd:documentation>
              </xsd:annotation>
              <xsd:sequence>
                   <xsd:element name="RemoteHost" type="xsd:string"/>
                   <xsd:element name="RemotePort" type="xsd:int"/>
                   <xsd:element name="MyName" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
    </xsd:schema>

    have you tried it with only 1 complexType in the xsd with the element?
    I have an xsd with many complexTypes and found that the root element was not what i thought it was (ie in your case ConfigInfo) and was having to append an xml tag at the start and end.
    Don't know if it's something to do with the new version of JAXB as the one with 1.6 is the only one i have used...
    m

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

  • Java 6, JAXB 2 and X3D (version 3.0)

    Hi everyone,
    I'm trying to unmarshall a X3D file using JAXB2 included in Java 6. I successfully generated the classes from the schema (http://www.web3d.org/specifications/x3d-3.0.xsd). I then created a simple X3D file using Blender and the Duke model available at https://duke.dev.java.net/models/Duke.lwo.
    However, when I try to unmarshall the model I get an exception. The X3D-file validates correctly using the validator in IntelliJ IDEA, but JAXB seems to fail somehow.
    The code used for unmarshalling:
    public static X3D loadModel(File input) {
        X3D model = null;
        try {
            JAXBContext context = JAXBContext.newInstance();
            Unmarshaller unmarshaller = context.createUnmarshaller();
            unmarshaller.setSchema(null);
            unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
            model = (X3D) unmarshaller.unmarshal(input);
        } catch (Exception e) {
            e.printStackTrace();  // TODO Fix exception handling.
        return model;
    }The Exception I get is:
    DefaultValidationEventHandler: [FATAL_ERROR]: unexpected element (uri:"", local:"X3D"). Expected elements are (none)
    Location: line 4 of file:/C:/Projects/JFokus/jfokus-demos/jogl-presentation/Duke.x3d
    javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"X3D"). Expected elements are (none)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:523)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:199)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:194)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:71)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:920)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:366)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:347)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:101)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
         at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:767)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3084)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
         at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:194)
         at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:167)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:142)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:151)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:169)
         at se.jsolutions.jogl.X3dModel.loadModel(X3dModel.java:27)
         at se.jsolutions.jogl.X3dModel.main(X3dModel.java:37)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    Done!
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
    Tried with other X3D-models I found online, with the same result. Any suggestions or help would be greatly appreciated.
    Thanks!
    // Erik

    public static X3D loadModel(File input) {
       X3D model = null;
       try {
          JAXBContext context = JAXBContext.newInstance(model.getPackage().getName());
          Unmarshaller unmarshaller = context.createUnmarshaller();
          model = (X3D) unmarshaller.unmarshal(input);
       } catch (Exception e) {
          e.printStackTrace();  // TODO Fix exception handling.
       return model;
    }

  • JAXB unmarshalling problem

    Hi
    I have a problem with unmarshalling.
    when my XML document is valide ,there is no probem but when the document is not valid(for exemple i put a String value in an element of type xs:decimal) i get a strange result:I thought that i will get a java.lang.NumberFormatException when i set the java attribute mapped with that element or i get the error value but this attribute get null as value and there is no NumberFormatException.

    riadhhwajdii wrote:
    Is there any way to modify this default behavior for jaxb to make it show the error value or get a java exceptionyes, see [this post|http://forums.sun.com/thread.jspa?messageID=11031834#11031834]
    Edited by: jtahlborn on Aug 8, 2010 10:01 AM

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

  • Jaxb unmarshalling: how to ignore unknown elements?

    Hi,
    I use jaxb 1.1 for communication with an external partner. (Took schema, compiled it, used generated classes for unmarshalling like this:
    Document doc = /* some document building */
    JAXBContext jaxbContext = JAXBContext.newInstance(MyConstants.JAXB_PACKAGE);
    Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();
    myObject = (MyObject) unMarshaller.unmarshal(doc);) Everything worked fine until they decided to add new elements to their xml-Document without notifiing me (nothing very unusual I think...). Now I get a javax.xml.bind.UnmarshallingException with Message "Unexpected Element". Is there any way to ignore such elements and just take the known Elements from the xml-stream?
    Thanks in advance
    Thomas

    Update your schema with the following after you known elements.
    <xs:any namespace="##any" processContents="skip" minOccurs="0" maxOccurs="unbounded">
    <xs:annotation>
    <xs:documentation>An extension point for arbitrary xml value fragments</xs:documentation>
    </xs:annotation>
    </xs:any>
    Hunter

  • JAXB Unmarshall Validation Error Handling

    Hello,
    During unmarshalling, if say a required element is missing, a ValidationEvent is created and passed to the handleEvent(ValidationEvent e) method of a custom class implementing the ValidationEventHandler interface.
    From the ValidationEvent, one can get the ValidationEventLocator, which allows you to find out the column and row numbers of where the validation failed in the XML file.
    The problem is, this XML file that is being unmarshalled/marshalled is hidden from the user and not allowed to be accessed directly. I would like to tell the user where the validation failed by referencing nodes instead of column/line numbers.
    For example, if an element called 'foo' requires one child 'bar', and if 'bar' is discovered as missing during unmarshalling, the message that comes with the ValidationEvent will say:
    uncompleted content model. expecting: <bar>
    I don't see a way to find out exactly where in the entire XML file that 'bar' is supposed to occure. How do I find out that the 'bar' element is expected to be under 'foo' element?
    Using the Eclipse debugger, I can see that the parent 'foo' is referenced somewhere deep within the JAXB impl classes, but I don't see any public methods that will allow me to get it.
    Any ideas?
    Thanks,
    AJ

    Try 'ValidationEventLocation.getObject()', and see if you can narrow it down from there.
    I'm also looking for a better solution, since I have a case where a child element is violating it's pattern restrictions, but all I get is a reference to the parent, with no apparent indication as to which child is at fault.

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

    Hi,
    I'm using JAXB 1.0-ea on W2K Server and have noticed that when I first unmarshal a 1KB file it takes 800ms. I then immediately unmarshall a 26KB file and it takes 400ms.
    I'm wondering if somebody has any ideas as to why the 1KB file is taking twice as long to unmarshall as the 26KB file?
    thanks,
    Dean

    I have 2 XML files, file A is 1KB and file B is 26KB. File A is exactly the same structure as file B with no difference in complexity or depth of the XML structures, its only shorter.
    When I load these 2 files in a loop the timings I get are kinda interesting, as this is what I see:
    File A: 590ms
    File B: 340ms
    File A: 16ms
    File B: 110ms
    File A: 0ms
    File B: 80ms
    File A: 0ms
    File B: 31ms
    File A: 0ms
    File B: 125ms
    File A: 0ms
    File B: 220ms
    The above timings are for the unmarshalling of the XML file, eg MyRootElement.unmarshal(fileInputStream);
    So, does anybody have any ideas why loading file A is taking so long on the first load, and nothing on subsequent loads? I'm using JAXB 1.0-ea on W2K using JDK1.4.1.
    thanks,
    Dean

  • JAXB unmarshall problem - beginner

    Hi Im having real pain trying to get unmarshall to work with JAXB with a very simple set up..
    My DTD looks like
    <!ELEMENT CXMLRESULT (MESSAGE)>
    <!ELEMENT MESSAGE (#PCDATA)>
    and xjs like
    <xml-java-binding-schema version="1.0ea">
    <element name="CXMLRESULT" type="class" root="true">
    </xml-java-binding-schema>
    I create an object marshall it and output to a file.. All looks good. This results in the following in the file..
    <CXMLRESULT>
    <MESSAGE>hello</MESSAGE></CXMLRESULT>
    However when I try to read in that file and unmarshall it I run into problems.. Although I receive NO error during the unmarshall, when I do a toString() afterwards then it does not display the MESSAGE element, and similarly trying to validate the object says that MESSAGE hasn't been detected.. I cannot figure out why this is.. The file was written out by JAXB so how come it cant read it back in.. For my unmarshall I do ...
    CXMLRESULT cxmlresult=new CXMLRESULT();
    try{
    try{
    input=new File("/in.xml");
    fileInputStream=new FileInputStream(input);
    } catch (IOException e)
    { System.out.println("error with file"); }
    cxmlresult.unmarshal(fileInputStream);
    } catch(UnmarshalException e) {
    e.printStackTrace();
    System.out.println(cxmlresult.toString());
    Doing this just shows a CXMLRESULT and not the MESSAGE element..
    Any ideas ?
    Mark

    Try this:
    CXMLRESULT cxmlresult = CXMLRESULT.unmarshal(fileInputStream);Dave

Maybe you are looking for

  • Java.lang.Error: java.util.zip.ZipException: The system cannot find the fil

    I got maven 221 installed i got jdk 1.6 and 1.5 installed (have tested both) I have a strange error. All my co-workers can build but I cant. The only thing I can find is that I dont have installed BEA Weblogic but I dont want to have that installed.

  • Arabic Problem in Indesign CS5 ME ???

    Hi, I am planning to publish a book about coins written in arabic. That's why I have to use latin and arabic letters in the same page. I just installed trial version of Indesign (7) CS5-ME. I creat a text box with "ME Type Tool"  and choose either Ad

  • Tips required for SAP XI online training from SAP eductaion partner?

    Hi, Recently I have registered for SAP XI course through online from SAP education partner. I would like to have some advice/share some experience to me for taking the online course effectively am a working person and will be able to spend only 2.5 h

  • Problem with Forums and Points

    Currently there is an issue in the forums with points - be aware that this is beeing investigated with the highest priority.

  • Disc to reset elements 11

    i want a disc to reset elements 11 which has been lost from my PC. impossible to download assistant . terribly frustrated .thanks MG