UnmarshalException in JAXB

I have two schemas, in one schema I have xs:any element. I could create Java objects using XJC without any problem.
But when I unmarshal I get below exception.
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: http://www.w3.org/TR/xml-schema-1#cvc-complex
-type.2.4.a?note3&{WC["http://www.w3.org/2001/XMLSchema"]}]
TestSchema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="rootType">
<xs:sequence>
<xs:element name="note1" type="xs:string"/>
<xs:element name="note2" type="xs:string"/>
<xs:any namespace="http://www.w3.org/2001/XMLSchema"
processContents="skip" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="root" type="rootType"/>
</xs:schema>
TestSchema_1.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="rootType">
<xs:all>
<xs:element name="note3" type="xs:string"/>
</xs:all>
</xs:complexType>
<xs:element name="root" type="rootType"/>
</xs:schema>
TestSchema.xml
<?xml version="1.0" encoding="Shift_JIS" standalone="yes"?>
<root>
<note1>String</note1>
<note2>String</note2>
<note3>asdf</note3>
</root>
Java Code
SchemaFactory scf = SchemaFactory.newInstance
(XMLConstants.W3C_XML_SCHEMA_NS_URI);
File xsd1 = new File("TestSchema.xsd");
File xsd2 = new File("TestSchema_1.xsd");
StreamSource[] sources = new StreamSource[2];
sources[0] = new StreamSource(xsd1);
sources[1] = new StreamSource(xsd2);
Schema schema = scf.newSchema(sources);
JAXBContext jc = JAXBContext.newInstance("generated");
Unmarshaller u = jc.createUnmarshaller();
u.setSchema(schema);
JAXBElement<?> rootElement = (JAXBElement<?>) u.unmarshal
(new FileInputStream("TestSchema.xml"));
RootType root = (RootType) rootElement.getValue();I could not find where is the problem. Could some one help please?

Hello.
You have to add to the classpath only these libs jaxb-api.jar, jaxb-libs.jar, jaxb-ri.jar, jaxb-xjc.jar for the proper application work. You should change your code if it depends on the old jaxb libs.
Good luck.

Similar Messages

  • JAXB UnmarshalException

    Hi all,
    I am using JDeveloper11g to unmarshall a XML file into a set of java classes.
    Initially I was able to generate the classes using JDeveloper11g, using JAXB 2.0 model from XML Schema. [using eclipselink]
    The classes generated were
    jaxb.properties
    ObjectFactory.java
    package-info.java
    Path.java
    so I wrote an extra class with main method to unmarshall a sample XML (of that schema) but it threw the following errors:
    javax.xml.bind.UnmarshalException
    - with linked exception:
    [Exception [EclipseLink-25008] (Eclipse Persistence Services - 1.1.1.v20090430-r4097): org.eclipse.persistence.exceptions.XMLMarshalException
    Exception Description: A descriptor with default root element path was not found in the project]
    As inidcated the "path" element descriptor was not found, but the class was generated.
    Please advise on possible causes and solutions (if any)
    A big advance thank you to all who help :)
    yee thian

    I suspect that something, somewhere, is treating those file names as if they were components of a URL. I say that because the characters you named in your post title all have special meanings in a URL.
    So you might have to URL-escape your file name, or there might be some other special thing you have to do. I don't know anything specifically about JAXB or about your application, but that's what I would investigate.

  • JAXB UnmarshalException - Filename w/ # or ? or %

    I have a requirement to allow file names with a set of non alpha numeric characters (except /). All of them seem to do fine except for filenames with the characters # or ? or % when it comes time to unmarshal the xml file. The error displayed below is for a file with the name: 2#2.txt.xml
    I have traced through my code and the file path and full name remain intact and the file is verified as being on the system. When I get to the call below in the code, the application throws the JAXB Exception shown below:      
    // Unmarshall the data in the file
         object = getUnmarshalledObject( unmarshaller.unmarshal( file ) );
    I am using JAXB 2.0
    Is there a way to get the JAXB Unmarshaller to recognize these special characters?
    I receive the JAXB Exception:
    javax.xml.bind.UnmarshalException
    - with linked exception:
    [java.io.FileNotFoundException: \var\data\EMU1.EMUApplication\.metadata\2 (The system cannot find the file specified.)]
         at javax.xml.bind.UnmarshalException.<init>(UnmarshalException.java:56)
    Complete Method:
         JAXBContext jaxbContext;
         Unmarshaller unmarshaller;
         Object object;
         // Make sure the file exists, is a file and is readable
         if ( ! file.exists() ) throw new OnsConfigException("Missing document file " + file.getAbsolutePath() );
         if ( ! file.canRead() ) throw new OnsConfigException("Non readable document file " + file.getAbsolutePath() );
         if ( file.isDirectory() ) throw new OnsConfigException("Cannot unmarshall directory " + file.getAbsolutePath() );
         try {
         // Create the context
         jaxbContext = JAXBContext.newInstance( packageName );
         // Create the unmarshaller
         unmarshaller = jaxbContext.createUnmarshaller();
         // Enable/disable validation
         unmarshaller.setSchema( schema );
         // Unmarshall the data in the file
         object = getUnmarshalledObject( unmarshaller.unmarshal( file ) );
         } catch (JAXBException jaxbExc) {
         // Rethrow as ONS exception
         jaxbExc.printStackTrace();
         throw new OnsConfigException( "XML Parse File Error", jaxbExc );
         } catch (Throwable e) {
         // Rethrow as ONS exception
         e.printStackTrace();
         throw new OnsConfigException( "XML Unmarshal File System Error", e );      
         }Thank you for your assistance.
    Edited by: Barbara5 on May 7, 2009 11:10 PM

    I suspect that something, somewhere, is treating those file names as if they were components of a URL. I say that because the characters you named in your post title all have special meanings in a URL.
    So you might have to URL-escape your file name, or there might be some other special thing you have to do. I don't know anything specifically about JAXB or about your application, but that's what I would investigate.

  • JAXB javax.xml.bind.UnmarshalException: Unexpected end of element

    I'm getting the following UnmarshalException when I try to run Unmarshaller.unmarshal from the command line but not when I run it in WSAD:
    2006-04-20 16:11:54,680 REPOST ERROR [main] (RestrictedListResponseConsumer.java:111) javax.xml.bind.UnmarshalException: Unexpected end of element {}:origin_country
            at com.b.watchdog.jaxb.generated.response.impl.runtime.SAXUnmarshallerHandlerImpl.handleEvent(SAXUnmarshallerHandlerImpl.java:580)
            at com.b.watchdog.jaxb.generated.response.impl.runtime.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:139)
            at com.b.watchdog.jaxb.generated.response.impl.runtime.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:136)
            at com.b.watchdog.jaxb.generated.response.impl.runtime.AbstractUnmarshallingEventHandlerImpl.unexpectedLeaveElement(AbstractUnmarshallingEventHandlerImpl.java:153)
            at com.b.watchdog.jaxb.generated.response.impl.runtime.AbstractUnmarshallingEventHandlerImpl.leaveElement(AbstractUnmarshallingEventHandlerImpl.java:63)
            at com.b.watchdog.jaxb.generated.response.impl.MessageHeaderTypeImpl$Unmarshaller.leaveElement(MessageHeaderTypeImpl.java:245)
            at com.b.watchdog.jaxb.generated.response.impl.runtime.SAXUnmarshallerHandlerImpl.endElement(SAXUnmarshallerHandlerImpl.java:141)
            at org.iso_relax.verifier.impl.ForkContentHandler.endElement(ForkContentHandler.java:81)
            at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
            at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
            at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
            at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
            at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
            at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
            at com.b.watchdog.jaxb.generated.response.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140)
            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)
            at com.b.watchdog.RestrictedListResponseConsumer.consumeResponse(RestrictedListResponseConsumer.java:81)
            at com.b.watchdog.RestrictedListResponseConsumer.consumeResponses(RestrictedListResponseConsumer.java:52)
            at com.b.watchdog.RestrictedListInterfaceManager.exchangeData(RestrictedListInterfaceManager.java:307)
            at com.b.watchdog.RestrictedListInterfaceManager.main(RestrictedListInterfaceManager.java:282)My message is:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <list_update_response xsi:schemaLocation="http://www.ab.com list_update_response.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ab.com">
         <response_info>
              <message_header>
                   <origin_country>FR</origin_country>
                   <destination_country>US</destination_country>
                   <message_datetime>2006-04-18T19:02:00.000+00:00</message_datetime>
              </message_header>
         </response_info>
         <success>
              <request_info>
                   <message_header>
                        <origin_country>US</origin_country>
                        <destination_country>FR</destination_country>
                        <message_datetime>2006-04-20T18:40:31.000+00:00</message_datetime>
                   </message_header>
              </request_info>
         </success>
    </list_update_response>My XSDs are:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ab.com" xmlns="http://www.ab.com">
         <xsd:include schemaLocation="list_update_common.xsd" />
         <xsd:element name="description" type="positive_length_token" />
         <xsd:element name="error">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element minOccurs="0" ref="request_info" />
                        <xsd:element ref="errors" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="errors">
              <xsd:complexType>
                   <xsd:choice maxOccurs="unbounded" minOccurs="1">
                        <xsd:element ref="validation_error" />
                        <xsd:element ref="general_logical_error" />
                        <xsd:element ref="item_logical_error" />
                   </xsd:choice>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="general_logical_error">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="description" />
                        <xsd:element minOccurs="0" ref="line_number" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="item_logical_error">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="description" />
                        <xsd:element minOccurs="0" ref="line_number" />
                   </xsd:sequence>
                   <xsd:attribute name="item_id" type="item_id" use="required" />
                   <xsd:attribute name="item_creation_country" type="country_code" use="required" />
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="line_number" type="xsd:positiveInteger" />
         <xsd:element name="list_update_response">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="response_info" />
                        <xsd:choice>
                             <xsd:element ref="error" />
                             <xsd:element ref="success" />
                        </xsd:choice>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="response_info">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="message_header" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="success">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="request_info" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="validation_error">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="description" />
                        <xsd:element ref="line_number" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
    </xsd:schema>
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ab.com" xmlns="http://www.ab.com">
         <xsd:simpleType name="country_code">
              <xsd:restriction base="xsd:string">
                   <xsd:pattern value="[A-Z]{2}" />
              </xsd:restriction>
         </xsd:simpleType>
         <xsd:element name="destination_country" type="country_code" />
         <xsd:simpleType name="item_id">
              <xsd:restriction base="xsd:string">
                   <xsd:pattern value="[A-Z0-9]{12}" />
              </xsd:restriction>
         </xsd:simpleType>
         <xsd:element name="message_datetime" type="utc_datetime" />
         <xsd:element name="message_header">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="origin_country" />
                        <xsd:element ref="destination_country" />
                        <xsd:element ref="message_datetime" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="origin_country" type="country_code" />
         <xsd:simpleType name="positive_length_token">
              <xsd:restriction base="xsd:token">
                   <xsd:minLength value="1" />
              </xsd:restriction>
         </xsd:simpleType>
         <xsd:element name="request_info">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="message_header" />
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:simpleType name="utc_datetime">
              <xsd:restriction base="xsd:dateTime">
                   <xsd:pattern value=".*(\+00\:00|\-00\:00|Z)" />
              </xsd:restriction>
         </xsd:simpleType>
    </xsd:schema>Any thoughts?
    Thanks.
    - Luke

    I fixed the problem.

  • JAXB - Unexpected end of element {} - UnmarshalException Exception

    Hi
    I am using Jaxb 1.0 Beta on AIX an I am getting javax.xml.bind.UnmarshalException exception when I try to unmarshall XML document. XML document and schema are valid ( I generated both using XML spy )
    Interestingly, the code works fine on windows 2000 but when I put the jar ,XML schema and xml document on unix it throws Unmarshall exception.
    Here's what I am trying to do.
    Code :
    JAXBContext jc =
    JAXBContext.newInstance( context,
    new com.xyz.retail.app.points.pgp.JAXBClassLoader());
    if(jc != null)
         System.out.println("Got the context");
    else
         System.out.println("Error in getting context");
    System.out.println("");
    // create an Unmarshaller
    Unmarshaller u = jc.createUnmarshaller();
    System.out.println("Created the Unmarshaller");
    System.out.println("");
    // Unmarshal securities document into Java content tree
    SecurityInfo securityInfo =
         (SecurityInfo)u.unmarshal( new FileInputStream( secFile ) );
    System.out.println("Unmarshaled the Document");
    System.out.println("");
    Schema :
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSPY v5 rel. 2 U (http://www.xmlspy.com) by Yogesh
    -->
    <xs:schema targetNamespace="http://www.xyz.com/retail/app/points/pgp/util"
    xmlns="http://www.xyz.com/retail/app/points/pgp/util" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="SecurityInfo" type="SecurityInfoType"/>
    <xs:complexType name="SecurityInfoType">
    <xs:sequence>
    <xs:element ref="AirlinePartners"/>
    </xs:sequence>
    </xs:complexType>
    <xs:element name="AirlinePartners">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="AirlinePartner" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="AirlinePartner">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="CardType" type="xs:string"/>
    <xs:element name="Description" type="xs:string" minOccurs="0"/>
    <xs:element name="TPrivate" type="xs:string"/>
    <xs:element name="TPassphrase" type="xs:string"/>
    <xs:element name="APublic" type="xs:string"/>
    <xs:element name="PlainText" type="xs:string"/>
    <xs:element name="CypherText" type="xs:string"/>
    <xs:element name="TKeyExpiry" type="xs:date" min
    Occurs="0"/>
    <xs:element name="AKeyExpiry" type="xs:date" min
    Occurs="0"/>
    </xs:sequence>
    </xs:complexType>
    /xs:element>
    </xs:schema>
    XML File :
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSPY v5 rel. 2 U (http://www.xmlspy.com) by Yogesh
    -->
    <!--Sample XML file generated by XMLSPY v5 rel. 2 U (http://www.xmlspy.com)-->
    <SecurityInfo xmlns="http://www.xyz.com/retail/app/points/pgp/util"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
    "http://www.xyz.com/retail/app/points/pgp/util /home/lcards/temp/APSecInfo.xsd">
    <AirlinePartners>
    <AirlinePartner>
    <CardType>x</CardType>
    <Description>some card</Description>
    <TPrivate>/home/lcards/temp/sachin.asc</TPrivate>
    <TPassphrase>worldcup2003</TPassphrase>
    <APublic>/home/lcards/temp/sunil.asc</APublic>
    <PlainText>/home/lcards/files/outbox/x</PlainText>
    <CypherText>/home/lcards/files/outbox/x</CypherText>
    <TKeyExpiry>2005-08-15</TKeyExpiry>
    <AKeyExpiry>2005-08-15</AKeyExpiry>
    </AirlinePartner>
    <AirlinePartner>
    <CardType>y</CardType>
    <Description>Another card</Description>
    <TPrivate>/home/lcards/temp/kapil.asc</TPrivate>
    <TPassphrase>worldcup1983</TPassphrase>
    <APublic>/home/lcards/temp/dilip.asc</APublic>
    <PlainText>/home/lcards/files/outbox/y</PlainText>
    <CypherText>/home/lcards/files/outbox/y</CypherText>
    <TKeyExpiry>2005-08-15</TKeyExpiry>
    <AKeyExpiry>2005-08-15</AKeyExpiry>
    </AirlinePartner>
    </AirlinePartners>
    </SecurityInfo>
    Output:
    Got the context
    Created the Unmarshaller
    DefaultValidationEventHandler: [ERROR]: Unexpected end of element {}:CardType
    javax.xml.bind.UnmarshalException: Unexpected end of element {}:CardType
    at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalExce
    ption(UnreportedException.java:59)
    at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThr
    ow(SAXUnmarshallerHandlerImpl.java:406)
    at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.endElement(S
    AXUnmarshallerHandlerImpl.java:108)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknow
    n Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
    Dispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
    known Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(Unmarshaller
    Impl.java:139)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnm
    arshallerImpl.java:129)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnm
    arshallerImpl.java:166)
    at com.xyz.retail.app.points.pgp.APSecurityInfoFactory.getAPSecInfo
    (APSecurityInfoFactory.java:102)
    at com.xyz.retail.app.points.pgp.EncryptAndSign.init(EncryptAndSign
    .java:183)
    at com.xyz.retail.app.points.pgp.EncryptAndSign.encrypt(EncryptAndS
    ign.java:581)
    at com.xyz.retail.app.points.pos.CreateExportFiles.main(CreateExpor
    tFiles.java:149)
    Inside readKeys()
    java.lang.NullPointerException
    at com.xyz.retail.app.points.pgp.EncryptAndSign.readKeys(EncryptAnd
    Sign.java:215)
    at com.xyz.retail.app.points.pgp.EncryptAndSign.encrypt(EncryptAndS
    ign.java:583)
    at com.xyz.retail.app.points.pos.CreateExportFiles.main(CreateExpor
    tFiles.java:149)
    Inside buildCypherTextFileName()
    java.lang.NullPointerException
    at com.xyz.retail.app.points.pgp.EncryptAndSign.buildCypherTextFile
    Name(EncryptAndSign.java:311)
    at com.xyz.retail.app.points.pgp.EncryptAndSign.encrypt(EncryptAndS
    ign.java:667)
    at com.xyz.retail.app.points.pos.CreateExportFiles.main(CreateExpor
    tFiles.java:149)
    Exception in Main method
    Thanks in advance for any help.
    Yogesh.

    I'm having error. I'm using the lastest JWSDP (1.3) with JDK 1.4.2
    Here is my XML file:
    <?xml version="1.0"?>
    <dataQA>
    <table name="ELECTORAL_DISTRICT" >
    <rules>
    <rule number="1.1" description="Check if we have 301 EDs" >
    <query result="301" >
         <sql>SELECT COUNT(ED_ID) FROM ELECTORAL_DISTRICT</sql>
    </query>
    </rule>
    <rule number="1.3" description="All fields must be populated" >
    <query result="0" >
    <sql>SELECT COUNT(ED_ID) FROM ELECTORAL_DISTRICT WHERE ED_CODE IS NULL OR ED_NAMEE IS NULL OR ED_NAMEF IS NULL</sql>
    </query>
    </rule>
    </rules>
    <reports>
    <report number="1.4" name="Listing of EDs" file="ed_list" format="HTML" >
         <column name="ED_ID" label="ID" ></column>
         <column name="ED_CODE" label="Code" ></column>
         <column name="ED_NAMEE" label="English Name" ></column>
         <column name="ED_NAMEF" label="French Name" ></column>
         <column name="PRVNC_ID" label="Province ID" ></column>
    </report>
    </reports>
    </table>
    </dataQA>
    And my shema:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="dataQA" type="DataQAType"/>
    <xsd:complexType name="DataQAType">
    <xsd:sequence>
    <xsd:element name="table" type="TableType" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="TableType">
    <xsd:sequence>
    <xsd:element name="rules" type="RulesType" />
    <xsd:element name="reports" type="ReportsType" />
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string" />
    </xsd:complexType>
    <xsd:complexType name="RulesType">
    <xsd:sequence>
    <xsd:element name="rule" minOccurs="1" maxOccurs="unbounded" >
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="query" type="QueryType" />
    </xsd:sequence>
    <xsd:attribute name="number" type="xsd:string" />
         <xsd:attribute name="description" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="ReportsType">
    <xsd:sequence>
    <xsd:element name="report" minOccurs="1" maxOccurs="unbounded" >
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="column" type="ColumnType" minOccurs="1" maxOccurs="unbounded" />
    <xsd:element name="condition" type="xsd:string" />
    </xsd:sequence>
    <xsd:attribute name="number" type="xsd:string" />
    <xsd:attribute name="name" type="xsd:string" />
    <xsd:attribute name="file" type="xsd:string" />
    <xsd:attribute name="format" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="ColumnType">
    <xsd:attribute name="name" type="xsd:string" />
    <xsd:attribute name="label" type="xsd:string" />
    </xsd:complexType>
    <xsd:complexType name="QueryType">
    <xsd:sequence>
    <xsd:element name="sql" type="xsd:string" />
    </xsd:sequence>
    <xsd:attribute name="result" type="xsd:string" />
    </xsd:complexType>
    </xsd:schema>
    I get the following exception:
    DefaultValidationEventHandler: [FATAL_ERROR]: Unexpected end of element {}:report
    Location: line 23 of file:/D:/Revise2.5/DataQA/config/test.xml
    javax.xml.bind.UnmarshalException: Unexpected end of element {}:report
    I'm currenlty in the processing of writting parser with DOM since I haven't found the yet. Is this a bug or I'm doing something wrong.
    Thanks in advance for the reply,
    - N. Thomassin

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

  • JAXB Implemetation

    Hi All,
    I have a few doubts related to the above mentioned topic. Any help would be greatly appreciated.
    Doubt 1
    We are trying to use JAXB to implement Mapping Program in Java. I was wondering as to how and where should we put those files in the XI server.
    To explain it further :
    We have extracted all JAXB related and Mapping Application related files into a single folder and imported that folder as an archive into the XI Framework within the Software Component Version Namespace in the Integration Builder (Design). But, the message mapping in the SXMB_MONI is showing the following stack:
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:ErrorHeader xmlns:SAP="http://sap.com/exchange/MessageFormat">
      <SAP:Context />
      <SAP:Code p1="Error during mapping" p2="--- Creating Java mapping com/wk/sapcl/mf/translator/source/SourceTranslator --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/ATOSTOSAP/666d2600d4e811d8c989d1fc143c3524/ --- Loaded class com.wk.sapcl.mf.translator.source.SourceTranslator --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/ATOSTOSAP/666d2600d4e811d8c989d1fc143c3524/ --- Load of javax/xml/bind/UnmarshalException.class from /sapmnt/XD1/global/xi/mapping/ATOSTOSAP/666d2600d4e811d8c989d1fc143c3524/ failed. --- Class not found: javax.xml.bind.UnmarshalException --- LinkageError at RUMappingJava.instantiate(): Could not instantiate class: com/wk/sapcl/mf/translator/source/SourceTranslator javax/xml/bind/UnmarshalException --- com.sap.aii.ibrun.server.map.MappingRuntimeException: at com.sap.aii.ibrun.server.map.MappingRuntimeException.code_STYLESHEET_OR_CLASS_NOT_FOUND(MappingRuntimeException.java:91) at com.sap.aii.ibrun.server.map.RUMappingJava.instantiate(RUMappingJava.java:158) at com.sap.aii.ibrun.server.map.RUMappingJava.execute(RUMappingJava.java:41) at com.sap.aii.ibrun.server.map.RURunner.run(RURunner.java:58) at com.sap.aii.ibrun.server.map.RUManager.run(RUManager.java:66) at com.sap.aii.ibrun.sbeans.map.MappingRequestHandler.handleRequest(MappingRequestHandler.java:67) at com.sap.aii.ibrun.sbeans.map.MappingServiceImpl.processFunction(MappingServiceImpl.java:83) at com.sap.aii.ibrun.sbeans.map.XMappingServiceObjectImpl0.processFunction(XMappingServiceObjectImpl0.java:24) at com.sap.aii.ibrun.sbeans.map.MappingServiceKey.processFunction(MappingServiceKey.java:10) at java.lang.reflect.Method.invoke(Native Method) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.invokeBean(RFCDefaultRequestHandler.java:83) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:50) at com.inqmy.services.rfcengine.RFCJCOServer.handleRequest(RFCJCOServer.java:69) at com.sap.mw.jco.JCO$Server.dispatchRequest(Unknown Source) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.nativeListen(Native Method) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.run(Unknown Source) at java.lang.Thread.run(Thread.java:513) ---" p3="" p4="">MAPPING.GENERIC</SAP:Code>
      <SAP:Text language="EN">Error during mapping</SAP:Text>
      </SAP:ErrorHeader>
    SourceTranslator is the mapping program. The UnmarshalException class is available in the archive.
    Can you please suggest that whether:
    1) JAXB related files should be available in the same archive or they should be in the Global Namespace ?
    2) Any clarifications that you may be reaching seeing the above dump?
    3) Any opinions on whether to go for JAXB, DOM, SAX for the mapping programs where IDoc's are involved?
    Doubt 2
    For the JAXB environment we exported the Target XSD for FIDCCP02 IDoc Type from the Integration Builder. The segment E1FIKPF has a MaxOccurs and MinOccurs defined as 1. Now these are the following issues:
    The IDoc segment can be replicated into the message mapping editor provided by XI. Thus, there can be multiple header level segments for E1FIKPF in a single IDoc. Then does that mean that XI does not validates the resultant OutputStream from the Mapping Program against the available XSD?
    If XI validates that against the output XSD how exactly are multiple segments allowed? I have cross checked the XSD after duplicating the segment and activating that mapping (taking the XSD from the Mapping Itself) for the multiple E1FIKPF, but,  there was only a single occurrence of that segment found and that too was with MaxOccurs, MinOccurs = 1?
    To make my JAXB libraries produce the similar output(with multiple header segments in a single IDoc) as is being done in the mapping editor, I need to modify the maxOccurs for that segment(E1FIKPF) as Unbounded. Now,
    1.     Can I somehow import this modified XSD into the XI environment ? ( I doubt that we can do that???)
    2.     If we cannot import this XSD, then with the validation occurring against this XSD how would XI take care of that?
    Doubt 3
    The XSD that is generated in XI environment refers to the namespace under which the IDoc definition was imported as a default namespace. The JAXB generated XML which is based on the XSD definition is expecting the XML to be in namespace of Integration Builder.
    But the input stream (XML) coming to the JAXB classes at the time of running is containing xmlns="atostosap" in the root element. This is the namespace name for which the code is being developed. Thus it results in Unmarhsall exception indicating the expected elements should be
    [{IB Namespace}Header_element_for_datatype].
    Any information on above would be of great help....
    Thanks in Advance
    Ashish Mittal

    Also, JAXB 2.0 Compilation with Tools>JAXB Compilation would be suitable.

  • Web services with JAXB

    Hi All,
    I am new to Web services with JAXB in ECLIPS.
    When I tried to unmarshal the XML file, I am getting the following exception.
    javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"order"). Expected elements are <{http://webservices/}read>,<{http://webservices/}readResponse>
         at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent
    xml , schema and java class are in follow.
    Please help me to solve this issue.
    Mohseni Rad.
    ----------------------------------po.xsd-----------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="order" type="OrderType"/>
    <xsd:complexType name="OrderType">
    <xsd:sequence>
    <xsd:element name="shipTo" type="xsd:string"/>
    <xsd:element name="billTo" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>
    ------------------------------------po.xml----------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <order>
    <shipTo>shipto</shipTo>
    <billTo>billto</billTo>
    </order>
    ------------------TestWS.java---------------------
    import java.io.FileInputStream;
    import java.io.IOException;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.Unmarshaller;
    import wsclient.*;
    public class TestWs {
         public static void main(String[] args) {
              try{
                   SecondWebServices webService = new SecondWebServicesService
    .getSecondWebServicesPort();
                   JAXBContext jctx = JAXBContext.newInstance("wsclient");
                   Unmarshaller unmarshaller = jctx.createUnmarshaller();
                   FileInputStream fl = new FileInputStream( "etc//po.xml" );
         JAXBElement<?> order = (JAXBElement<?>)unmarshaller.unmarshal( fl );
                   OrderType orderType = (OrderType)order.getValue();
                   webService.read( orderType);
              }catch (JAXBException je) {
                   je.printStackTrace();
              catch (IOException ioe) {
                   ioe.printStackTrace();
    }

    Hi,
    When you are using JAX-WS, there is a tool wsimport, with which you are going to generate the artifacts required to implement the web service.
    When you pass the WSDL as a parameter to the wsimport tool, it will be create the required beans also(JAXB Objects).
    So need of any other external implementation of JAXB when you are working with JAXWS
    Thanks,

  • Namespace error with JAXB

    Hello everyone! This is my problem:
    I am using jaxb to unmarshall a xml file. When I unmarshall, the program doesn�t work at this point:
    JAXBContext jc = JAXBContext.newInstance("com.claynet.core.clom");
    Unmarshaller u = jc.createUnmarshaller();
    u.setValidating(true);
    Clom clom =
    (Clom)u.unmarshal(
    new FileInputStream( ".." + File.separatorChar +
    "webapps"+ File.separatorChar + "claybrary" + File.separatorChar
    + "objetosCLOM" + File.separatorChar + file_name.trim()) );
    The error I get is the following one:
    javax.xml.bind.UnmarshalException: Probably namespace URI of tag "clom" is wrong (correct one is "http://www.clayformacion.com/xsd/clomv1.0")
    - with linked exception:
    [com.sun.msv.verifier.ValidityViolation: Probably namespace URI of tag "clom" is wrong (correct one is "http://www.clayformacion.com/xsd/clomv1.0")]
    The problem seems to be a conflict with the namespace, but the schema has the namespace correctly set:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:clom="http://www.clayformacion.com/xsd/clomv1.0" xmlns="http://www.clayformacion.com/xsd/clomv1.0" targetNamespace="http://www.clayformacion.com/xsd/clomv1.0" elementFormDefault="qualified">
    The validation inside the unmarshalling crash.
    Is there any errors with the code? Can Anyone help me?
    Thanks

    Looks like error is clear namespace mismatch...try changing the following url in wsdl and regen the code
    http://example.ws found http://example.ws/xsd

  • 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 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 XML Unmarshalling validation problem

    Hello,
    I'm using toplink JAXB to map XML document to an object hierarchy. The set of objects was built using Toplink workbench from the corresponding XSD file. The XSD file is specified in <toplink:resource> element using an absolute path. If I use unmarshaller validation (Unmarshaller u = jc.createUnmarshaller(); u.setValidating(true)) it works fine in embedded oc4j, but fails withan UnmarshalException "An internal error condition occurred" for Line N 1.
    It looks like the cause of the exception is that toplink cannot find the XSD file. I've tried to put the XSD file into META-INF and into classes directly, and specify the relative path, but it has failed event locally in the embedded oc4j.
    Everything works if I do not turn the validation on.
    Has anybody gotten the same issue? What could be a solution if we have to perform the validation?
    Thanks
    Kate

    Hello Kate,
    One possible work around would be use the TopLink OXM specific APIs for this unmarshal. For the most part they mirror the JAXB APIs so there usage is pretty straight forward.
    XMLContext xmlContext = new XMLContext(YOUR_JAXB_CONTEXT_PATH);
    xmlUnmarshaller = xmlContext.createUnmarshaller();One API that we offer that is not part of the standard JAXB Unmarshaller is the ability to specify an EntityResolver. This class allows you to override where the XML Schema is loaded from.
    EntityResolver entityResolver = new YourEntityResolver();
    xmlUmarshaller.setEntityResolver(entityResolver);YourEntityResolver must implement org.xml.sax.EntityResolver. There is one method on this interface that returns an InputSource representing the XML Schema. You can implement this method to load the Schema from a ClassLoader.
    -Blaise

  • JAXB Unmarshaller and errors to system.out

    Hi!
    I'm using JAXB in a complex XML binding project. The question is: is there a way to prevent javax.xml.bind.Unmarshaller to send to system.out the warnings/errors messages as DefaultValidationEventHandler: [ERROR]: bla bla bla
    which are sent immediately before to throw an UnmarshalException??
    Thanks so much!!

    Have you tried using System.setErr() and System.setOut() ? With these calls at the start of your application, you should be able to redirect the error to a file or whatever you want.

  • JAXB looking for tag type rather than tag name?

    Hi everyone.
    I'm trying to use JAXB to load an xml file, [http://www.unimod.org/xml/unimod.xml|http://www.unimod.org/xml/unimod.xml] . The schema is at [http://www.unimod.org/xmlns/schema/unimod_2/unimod_2.xsd|http://www.unimod.org/xmlns/schema/unimod_2/unimod_2.xsd] . I generate my classes using xjc with no problems. My unmarshalling code is simple enough:
    try {
        JAXBContext ctx = JAXBContext.newInstance(new Class[] {UnimodT.class});
        Unmarshaller um = ctx.createUnmarshaller();
        return (UnimodT) um.unmarshal(is);
    } catch (JAXBException ex) {
    }At first I got an exception saying that unimod (the top-level tag) is unexpected and that the expected element is (none). I solved this by adding the @XmlRootElement tag into my UnimodT class. Now I am getting a javax.xml.bind.UnmarshalException :
    "unexpected element (uri:"http://www.unimod.org/xmlns/schema/unimod_2", local:"unimod"). Expected elements are <{http://www.unimod.org/xmlns/schema/unimod_2}unimodT>"
    I am guessing this means that it is looking for a <unimodT> tag while the actual tag name is <unimod>.
    This is how the xml file starts:
    <umod:unimod xsi:schemaLocation="http://www.unimod.org/xmlns/schema/unimod_2 http://www.unimod.org/xmlns/schema/unimod_2/unimod_2.xsd" majorVersion="2" minorVersion="0">
        <umod:elements>
              ....and here is the fragment from the xml schema defining the root element:
         <xs:element name="unimod" type="umod:unimod_t">Other guesses I am having are:
    1) Maybe I should do something with the namespace, "umod"?
    2) The underscore in the type name is confusing xjc?
    Please help if you can. I am guessing it is something simple but I have no idea what.

    I seem to have solved my problem by adding the namespace and name of the tag on the XmlRootElement annotation:
    @XmlRootElement(name="unimod",namespace="http://www.unimod.org/xmlns/schema/unimod_2")however I still don't understand
    1) why it's not enough to specify the name of the tag in the @XmlType annotation
    2) why the @XmlRootElement tag was not specified automatically
    I guess I should just be happy that it works now.

  • JAXB binding for Boolean

    Hi,
    I'm using xml and JMS to query a remote system.
    One of the values in the remote system that I am interested in is a boolean value. I do not know this field is defaulted in the remote system so I want to use a Boolean object to represent it. I.e I want it to be null is no value is available in the remote system.
    Could any of you give me a quick run down on how to go abount doing this or point me to a tutorial.
    Is there another way of doing what I am trying to do?
    Appreciate any help.
    Cheers,
    Nim

    Hi James,
    Yup, I'm trying to process the xml returned by the remote system.
    The Boolean is an element and not an attribute:
    The schema i am using is shown below:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="accounts" type="AccountsType"/>
    <xsd:complexType name="AccountsType">
    <xsd:sequence>
    <xsd:element name="account" type="Account" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Account">
    <xsd:sequence>
    <xsd:element name="accountId" type="xsd:string"/>
    <xsd:element name="customerId" type="xsd:string"/>
    <xsd:element name="totalAmountOwing" type="xsd:decimal"/>
    <xsd:element name="amountOwing" type="xsd:decimal"/>
    <xsd:element name="totalArrears" type="xsd:decimal"/>
    <xsd:element name="paymentExtensionCount" type="xsd:integer"/>
    <xsd:element name="paymentHistoryIndicator" type="xsd:string"/>
    <xsd:element name="payDate" type="xsd:date"/>
    <xsd:element name="directDebitSchedule" type="xsd:boolean"/>
    <xsd:element name="easyPaySchedule" type="xsd:boolean"/>
    <xsd:element name="billIssueDate" type="xsd:date"/>
    <xsd:element name="arrearsDebtAge" type="xsd:integer"/>
    <xsd:element name="sourceSystemId" type="xsd:string"/>
    <xsd:element name="readFrequency" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>
    I have access to change the schema. I tried making the boolean an attribute as shown below:
    <xsd:element name="easyPaySchedule">
    <xsd:complexType>
    <xsd:sequence/>
    <xsd:attribute name="value" type="xs:boolean"/>
    </xsd:complexType>
    </xsd:element>
    but I could not see the isSetMethod in the jaxb account implementation file.
    I changed it back and added minOccurs="0":
    <xsd:element name="easyPaySchedule" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
    and started seeing the isSetMethod in the jaxb account implementation class but not the generated account interface.
    Next, I used the xjb file below:
    <jxb:bindings version="1.0"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="accounts.xsd" node="/xsd:schema">
    <jxb:bindings node="//xsd:complexType[@name='Account']">
    <jxb:bindings node=".//xsd:element[@name='easyPaySchedule']">
    <jxb:property generateIsSetMethod="true"/>
    </jxb:bindings>
    </jxb:bindings> <!-- node="//xsd:complexType[@name='Account'] -->
    </jxb:bindings> <!-- schemaLocation="accounts.xsd" node="/xsd:schema" -->
    </jxb:bindings>
    and I started seeing the isSet methods in the generated Account interface.
    I thought I was in the clear but when I try and run it with the xml below:
    <account>
    <accountId>11111111111</accountId>
    <customerId>2222222</customerId>
    <totalAmountOwing>123</totalAmountOwing>
    <amountOwing>12</amountOwing>
    <totalArrears>0</totalArrears>
    <paymentExtensionCount>1</paymentExtensionCount>
    <paymentHistoryIndicator>110111001111</paymentHistoryIndicator>
    <payDate>2004-10-08+10:00</payDate>
    <directDebitSchedule>false</directDebitSchedule>
    <easyPaySchedule></easyPaySchedule> <<<<<<------ blank instead of false/true
    <billIssueDate>2003-10-08+10:00</billIssueDate>
    <arrearsDebtAge>0</arrearsDebtAge>
    <sourceSystemId>cise</sourceSystemId>
    <readFrequency>Q</readFrequency>
    </account>
    I start to get the following exception:
    javax.xml.bind.UnmarshalException: Unexpected text ""
    - with linked exception:
    [java.lang.NullPointerException]
    Any ideas as to whats going on?
    Cheers,
    Nim

Maybe you are looking for

  • Minha página inicial muda toda vez que ligo o pc, ja fiz várias coisas, oq mais posso fazer?

    Ela esta definida como a página original do Mozilla Firefox, mas quando ligo o pc, ela abre a página "www.gamegoogle.com" mesmo a página padrão estando definida... No atalho, (ao clicar com o direito do mouse no ícone do Mozilla, tem uma linha após o

  • How can I edit the rules file?

    How can I develop my program which can access rules file?I know that Hyperion didn't provide APIs to set properties of rules files.

  • Time limit on imovie

    I am working with iMovie 11 for the first time and all was going well until my movie reached the 4:10 mark. Is there a setting I need to change? Any help is appreciated.

  • Business Functions Switch to activate Enhancement Package 4

    Hi SAP experts, can you help me?... We will implement SAP CRM 7.0 with scenario of creation ERP Quations & ERP Sales Orders, therefore we have installed Enhancement Package 4 in our ERP, but I've been looking for information to know which Business Fu

  • Lining up effects on text aligned to circle

    I'm working on text that will go on a cd. The text I'm trying to create is actually two sets of outlined text that have gradients and effects applied to them. The client wants the text aligned in an arc approach on the cd - so what I did is created a