users@jaxb.java.net

Unexpected element when unmarshalling abstract type

From: Hunter Stern <vonrosen2000_at_yahoo.com>
Date: Fri, 10 Mar 2006 23:07:57 -0800 (PST)

when unmarshalling following xml i get an Unexpected
element exception, all the details are below, thanks
in advance for your help. using jaxb 1.6 ri, jdk1.5

xml:

<?xml version="1.0"?>
<!--
  == Copyright (c) 2002-2004. All rights reserved.
  == Financial Products Markup Language is subject to
the FpML public license.
  == A copy of this license is available at
http://www.fpml.org/documents/license
  -->
<FpML version="4-1" xsi:type="DataDocument"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fpml.org/2004/FpML-4-1
../fpml-main-4-1.xsd"
xmlns="http://www.fpml.org/2004/FpML-4-1">
        <trade>
                <tradeHeader>
                        <partyTradeIdentifier>
                                <partyReference href="CHASE"/>
                                <tradeId
tradeIdScheme="http://www.chase.com/swaps/trade-id">TW9235</tradeId>
                        </partyTradeIdentifier>
                        <partyTradeIdentifier>
                                <partyReference href="BARCLAYS"/>
                                <tradeId
tradeIdScheme="http://www.barclays.com/swaps/trade-id">SW2000</tradeId>
                        </partyTradeIdentifier>
                        <tradeDate>1994-12-12</tradeDate>
                </tradeHeader>
                <swap>
                        <!-- Chase pays the floating rate every 6 months,
based on 6M DEM-LIBOR-BBA,
            on an ACT/360 basis -->
                        <swapStream>
                                <payerPartyReference href="CHASE"/>
                                <receiverPartyReference href="BARCLAYS"/>
                                <calculationPeriodDates
id="floatingCalcPeriodDates">
                                        <effectiveDate>
                                                <unadjustedDate>1994-12-14</unadjustedDate>
                                                <dateAdjustments>
                                                
<businessDayConvention>NONE</businessDayConvention>
                                                </dateAdjustments>
                                        </effectiveDate>
                                        <terminationDate>
                                                <unadjustedDate>1999-12-14</unadjustedDate>
                                                <dateAdjustments>
                                                
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                        <businessCenters id="primaryBusinessCenters">
                                                                <businessCenter>DEFR</businessCenter>
                                                        </businessCenters>
                                                </dateAdjustments>
                                        </terminationDate>
                                        <calculationPeriodDatesAdjustments>
                                        
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCentersReference
href="primaryBusinessCenters"/>
                                        </calculationPeriodDatesAdjustments>
                                        <calculationPeriodFrequency>
                                                <periodMultiplier>6</periodMultiplier>
                                                <period>M</period>
                                                <rollConvention>14</rollConvention>
                                        </calculationPeriodFrequency>
                                </calculationPeriodDates>
                                <paymentDates>
                                        <calculationPeriodDatesReference
href="floatingCalcPeriodDates"/>
                                        <paymentFrequency>
                                                <periodMultiplier>6</periodMultiplier>
                                                <period>M</period>
                                        </paymentFrequency>
                                
<payRelativeTo>CalculationPeriodEndDate</payRelativeTo>
                                        <paymentDatesAdjustments>
                                        
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCentersReference
href="primaryBusinessCenters"/>
                                        </paymentDatesAdjustments>
                                </paymentDates>
                                <resetDates id="resetDates">
                                        <calculationPeriodDatesReference
href="floatingCalcPeriodDates"/>
                                
<resetRelativeTo>CalculationPeriodStartDate</resetRelativeTo>
                                        <fixingDates>
                                                <periodMultiplier>-2</periodMultiplier>
                                                <period>D</period>
                                                <dayType>Business</dayType>
                                        
<businessDayConvention>NONE</businessDayConvention>
                                                <businessCenters>
                                                        <businessCenter>GBLO</businessCenter>
                                                </businessCenters>
                                                <dateRelativeTo href="resetDates"/>
                                        </fixingDates>
                                        <resetFrequency>
                                                <periodMultiplier>6</periodMultiplier>
                                                <period>M</period>
                                        </resetFrequency>
                                        <resetDatesAdjustments>
                                        
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCentersReference
href="primaryBusinessCenters"/>
                                        </resetDatesAdjustments>
                                </resetDates>
                                <calculationPeriodAmount>
                                        <calculation>
                                                <notionalSchedule>
                                                        <notionalStepSchedule>
                                                                <initialValue>50000000.00</initialValue>
                                                                <currency
currencyScheme="http://www.fpml.org/ext/iso4217">DEM</currency>
                                                        </notionalStepSchedule>
                                                </notionalSchedule>
                                                <floatingRateCalculation>
                                                
<floatingRateIndex>DEM-LIBOR-BBA</floatingRateIndex>
                                                        <indexTenor>
                                                                <periodMultiplier>6</periodMultiplier>
                                                                <period>M</period>
                                                        </indexTenor>
                                                </floatingRateCalculation>
                                                <dayCountFraction
dayCountFractionScheme="http://www.fpml.org/spec/2004/day-count-fraction-1-0">ACT/360</dayCountFraction>
                                        </calculation>
                                </calculationPeriodAmount>
                        </swapStream>
                        <!-- Barclays pays the 6% fixed rate every year on
a 30E/360 basis -->
                        <swapStream>
                                <payerPartyReference href="BARCLAYS"/>
                                <receiverPartyReference href="CHASE"/>
                                <calculationPeriodDates id="fixedCalcPeriodDates">
                                        <effectiveDate>
                                                <unadjustedDate>1994-12-14</unadjustedDate>
                                                <dateAdjustments>
                                                
<businessDayConvention>NONE</businessDayConvention>
                                                </dateAdjustments>
                                        </effectiveDate>
                                        <terminationDate>
                                                <unadjustedDate>1999-12-14</unadjustedDate>
                                                <dateAdjustments>
                                                
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                        <businessCentersReference
href="primaryBusinessCenters"/>
                                                </dateAdjustments>
                                        </terminationDate>
                                        <calculationPeriodDatesAdjustments>
                                        
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCentersReference
href="primaryBusinessCenters"/>
                                        </calculationPeriodDatesAdjustments>
                                        <calculationPeriodFrequency>
                                                <periodMultiplier>1</periodMultiplier>
                                                <period>Y</period>
                                                <rollConvention>14</rollConvention>
                                        </calculationPeriodFrequency>
                                </calculationPeriodDates>
                                <paymentDates>
                                        <calculationPeriodDatesReference
href="fixedCalcPeriodDates"/>
                                        <paymentFrequency>
                                                <periodMultiplier>1</periodMultiplier>
                                                <period>Y</period>
                                        </paymentFrequency>
                                
<payRelativeTo>CalculationPeriodEndDate</payRelativeTo>
                                        <paymentDatesAdjustments>
                                        
<businessDayConvention>MODFOLLOWING</businessDayConvention>
                                                <businessCentersReference
href="primaryBusinessCenters"/>
                                        </paymentDatesAdjustments>
                                </paymentDates>
                                <calculationPeriodAmount>
                                        <calculation>
                                                <notionalSchedule>
                                                        <notionalStepSchedule>
                                                                <initialValue>50000000.00</initialValue>
                                                                <currency
currencyScheme="http://www.fpml.org/ext/iso4217">DEM</currency>
                                                        </notionalStepSchedule>
                                                </notionalSchedule>
                                                <fixedRateSchedule>
                                                        <initialValue>0.06</initialValue>
                                                </fixedRateSchedule>
                                                <dayCountFraction
dayCountFractionScheme="http://www.fpml.org/spec/2004/day-count-fraction-1-0">30E/360</dayCountFraction>
                                        </calculation>
                                </calculationPeriodAmount>
                        </swapStream>
                </swap>
        </trade>
        <party id="CHASE">
                <partyId>CHASUS33</partyId>
        </party>
        <party id="BARCLAYS">
                <partyId>BARCGB2L</partyId>
        </party>
</FpML>

full xsd files are at:

http://exposurecontrol.com/~hstern/fpml/

fpml-asset-4-1.xsd fpml-fx-4-1.xsd
fpml-pr-shared-4-1.xsd
fpml-cd-4-1.xsd fpml-ird-4-1.xsd
fpml-pretrade-4-1.xsd
fpml-doc-4-1.xsd fpml-main-4-1.xsd
fpml-reporting-4-1.xsd
fpml-enum-4-1.xsd fpml-mktenv-4-1.xsd
fpml-riskdef-4-1.xsd
fpml-eq-shared-4-1.xsd fpml-msg-4-1.xsd
fpml-shared-4-1.xsd
fpml-eqd-4-1.xsd fpml-posttrade-4-1.xsd
fpml-tradeexec-4-1.xsd
fpml-eqs-4-1.xsd fpml-pr-4-1.xsd
xmldsig-core-schema.xsd


relevant xsd snippet for the concrete complex type
from the abstract type in fpml-doc-4-1.xsd:

        <xsd:complexType name="DataDocument">
                <xsd:annotation>
                        <xsd:documentation xml:lang="en">A type defining a
content model that is backwards compatible with older
FpML releases and which can be used to contain sets of
data without expressing any processing
intention.</xsd:documentation>
                </xsd:annotation>
                <xsd:complexContent>
                        <xsd:extension base="Document">
                                <xsd:sequence>
                                        <xsd:group ref="Validation.model"/>
                                        <xsd:choice>
                                                <xsd:sequence>
                                                        <xsd:element name="trade" type="Trade"
minOccurs="0" maxOccurs="unbounded">
........

        <xsd:complexType name="Document" abstract="true">
                <xsd:annotation>
                        <xsd:documentation xml:lang="en">The abstract base
type from which all FpML compliant messages and
documents must be derived.</xsd:documentation>
                </xsd:annotation>
                <xsd:attributeGroup ref="StandardAttributes.atts"/>

xsd of abstract type in fpml-doc-4-1.xsd:

        <xsd:complexType name="Document" abstract="true">
                <xsd:annotation>
                        <xsd:documentation xml:lang="en">The abstract base
type from which all FpML compliant messages and
documents must be derived.</xsd:documentation>
                </xsd:annotation>
                <xsd:attributeGroup ref="StandardAttributes.atts"/>
        </xsd:complexType>
.....

root element xsd in fpml-main-4-1.xsd:

        <xsd:element name="FpML" type="Document">
                <xsd:annotation>
                        <xsd:documentation xml:lang="en">The FpML element
forms the root for any conforming FpML instance
document. The actual structure of the document is
determined by setting the 'type' attribute to an
appropriate derived subtype of the complex type
Document.</xsd:documentation>
                </xsd:annotation>
        </xsd:element>

java program snippet which fails:

        JAXBContext jc =
JAXBContext.newInstance("com.riskman.fpml");

        Unmarshaller unmarshaller = jc.createUnmarshaller();

        FpMLElement f = (FpMLElement)unmarshaller.unmarshal(
new FileInputStream(
"C:\\downloads\\critical\\riskmansite\\hyperjaxbtest\\xml\\ird_ex01_vanilla_swap.xml"
) );


stack trace:

DefaultValidationEventHandler: [ERROR]: Unexpected
element {http://www.fpml.org/2004/FpML-4-1}:trade
     Location:
javax.xml.bind.UnmarshalException: Unexpected element
{http://www.fpml.org/2004/FpML-4-1}:trade
        at
com.riskman.fpml.impl.runtime.SAXUnmarshallerHandlerImpl.handleEvent(SAXUnmarshallerHandlerImpl.java:580)
        at
com.riskman.fpml.impl.runtime.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:139)
        at
com.riskman.fpml.impl.runtime.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:136)
        at
com.riskman.fpml.impl.runtime.AbstractUnmarshallingEventHandlerImpl.unexpectedEnterElement(AbstractUnmarshallingEventHandlerImpl.java:147)
        at
com.riskman.fpml.impl.runtime.AbstractUnmarshallingEventHandlerImpl.enterElement(AbstractUnmarshallingEventHandlerImpl.java:60)
        at
com.riskman.fpml.impl.FpMLElementImpl$Unmarshaller.enterElement(FpMLElementImpl.java:185)
        at
com.riskman.fpml.impl.runtime.AbstractUnmarshallingEventHandlerImpl.revertToParentFromEnterElement(AbstractUnmarshallingEventHandlerImpl.java:329)
        at
com.riskman.fpml.impl.DocumentImpl$Unmarshaller.enterElement(DocumentImpl.java:182)
        at
com.riskman.fpml.impl.FpMLElementImpl$Unmarshaller.enterElement(FpMLElementImpl.java:173)
        at
com.riskman.fpml.impl.runtime.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:126)
        at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
        at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
        at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
        at
com.riskman.fpml.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:178)
        at MainTest.deserializeXML(MainTest.java:54)
        at MainTest.process(MainTest.java:36)
        at MainTest.main(MainTest.java:24)
javax.xml.bind.UnmarshalException: Unexpected element
{http://www.fpml.org/2004/FpML-4-1}:trade


Hunter