Basically we are not able to type cast into child JAXB classes after retrieving the parent class list from root node
We are facing below issue while unmarshalling via JAXB 2.0
XSD Definition:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="
http://www.vzw.com/namespace/scm" xmlns:ipdr="
http://www.ipdr.org/namespaces/ipdr" xmlns="
http://www.vzw.com/namespace/scm" xmlns:xs="
http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="
http://www.ipdr.org/namespaces/ipdr" schemaLocation="../common/IPDRDoc3.1-SCM.xsd"/>
<xs:element name="itemPurchase" type="itemPurchaseType">
<xs:annotation>
<xs:documentation>For billing records t…….</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="itemPurchaseType">
<xs:complexContent>
<xs:extension base="revenueShareBillingEventType">
<xs:sequence>
<xs:element ref="vendorEventId"/>
……..
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="revenueShareBillingEventType">
<xs:complexContent>
<xs:extension base="ipdr:IPDRType">
<xs:sequence>
<xs:element ref="recordId"/>
…..
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Note IPDRType defined inside imported xsd: IPDRDoc3.1-SCM.xsd
Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<ipdr:IPDRDoc xmlns="
http://www.vzw.com/namespace/scm" xmlns:ipdr="
http://www.ipdr.org/namespaces/ipdr" xmlns:xsi="
http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="
http://www.vzw.com/namespace/scm SCMRevenueShare1.0.xsd" ………..>
<ipdr:IPDR xsi:type="itemPurchaseType">
<ipdr:seqNum>0</ipdr:seqNum>
…….
</ipdr:IPDR>
………………
</ipdr:IPDRDoc>
Unmarshalling using JAXB 2.0
JAXBContext jc = JAXBContext.newInstance( "net.com…." );
Unmarshaller u = jc.createUnmarshaller();
Object o = u.unmarshal( new File( "sample.xml" ) );
IPDRDoc doc = (IPDRDoc) o;
List<IPDRType> ipdrLst = doc.getIPDR();
Iterate throught List ipdrLst…
For each ipdr element:
ItemPurchaseType purchase = (ItemPurchaseType) ipdr;
I am getting class cast exception for above statement. How to retrieve purchase element from IPDRDoc?
[Message sent by forum member 'r1mohindra' (r1mohindra)]
http://forums.java.net/jive/thread.jspa?messageID=322623