Hi ,

I got one example which is provided url:

http://project.exolab.org/cgi-bin/viewcvs.cgi/castor/src/tests/RegressionTestSuite/xml/sourcegenerator/xsi-type/?cvsroot=castor

I think this would solve my problem which is posted earier unable to instatiate news object

When i try to unmarshall this input1.xml file i am getting
java.lang.IllegalStateException: java.lang.ClassCastException: com.emp.NodeA

root.xsd:

Code:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://testspace"
            elementFormDefault="qualified"
            version="1.0">


   <xs:complexType name="Root">
     <xs:sequence>
       <xs:element name="node" type="AbstractNode" minOccurs="1" maxOccurs="unbounded"/>
     </xs:sequence>
   </xs:complexType>

   <xs:complexType name="AbstractNode" abstract="true">
     <xs:attribute name="id" type="xs:int" />
   </xs:complexType>

   <xs:element name="NodeA">
     <xs:complexType>
     <xs:complexContent>
       <xs:extension base="AbstractNode">
         <xs:attribute name="typeAAttrib" type="xs:string" />
       </xs:extension>
     </xs:complexContent>
     </xs:complexType>
    </xs:element>

   <xs:element name="NodeB">
     <xs:complexType>
     <xs:complexContent>
       <xs:extension base="AbstractNode">
         <xs:attribute name="typeBAttrib" type="xs:string" />
       </xs:extension>
     </xs:complexContent>
     </xs:complexType>
   </xs:element>

</xs:schema>


roots.xml

Code:
<tst:root    xmlns:tst="http://testspace"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     <tst:node id="1" typeAAttrib="an attribute" xsi:type="tst:NodeA"/>
     <tst:node id="2" typeBAttrib="another attribute" xsi:type="tst:NodeB" />

</tst:root>


This java file is using to unmarshall this xsi:type

Code:
public class H3GNews implements PropertyChangeListener {


    public void propertyChange(PropertyChangeEvent event) {
        System.out.println("PropertyChange: " + event.getPropertyName());
    } //-- propertyChange

    public static void main(String[] args) {
   try {


       System.out.println("Unmarshalling Invoice");

       Root  root = null;
       System.out.println("Unmarshalling Invoice1111");
       FileReader reader=new FileReader("roots.xml");

       root = (Root)Root.unmarshal(reader);
         /***
         * Get the FeedMetaData Information
         */




    } catch (Exception e) {
       e.printStackTrace();
   }

    }

}


Castor properties file

Code:
org.exolab.castor.builder.javaclassmapping=type
#org.exolab.castor.builder.javaclassmapping=element
org.exolab.castor.validation=true
org.exolab.castor.indent=false
org.exolab.castor.debug=true


I am using castor-0.9.5.4.jar file. Could you please tell me how to unmarshall the above xml file.
 
Thanks & Regards
sudhakar goud.T


Confidentiality Notice

The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL PROTECTED] immediately
and destroy all copies of this message and any attachments.
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to