You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Eric Vasilik <er...@bea.com> on 2003/10/22 05:58:25 UTC

RE: java.lang.ClasssCastException

It's best to send questions like these to the public mailing list (mailto:xml-xmlbeans-user@apache.org).  You have a better chance of getting a prompt answer, and others can benefit from your issue.  (Plus, I can procrastinate in hope that someone else answers :-)

I assume you are getting a class case exception at the line:

     max = (UMAXDocument)XmlLoader.load(bookFile);

You are using a very old version of XmlBeans.  XmlLoader was removed quite some time ago.  Depending on the version you have, XmlLoader.load will not automatically detect the document type, thus your cast exception.

I recommend getting the latest V1 buld of xmlbeans:

    http://xml.apache.org/xmlbeans/

and use something like:

     max = UMAXDocument.Factory.parse(( bookFile );

- Eric

-----Original Message-----
From: luke [mailto:gqlu@hurray.com.cn]
Sent: Tuesday, October 21, 2003 10:01 AM
To: Eric Vasilik
Subject: java.lang.ClasssCastException


ericvasHey:
	I got your mail from xmlBeans maillist.
	I got a error when I use the xmlBeans,I define a xsd file like this:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="U-MAX">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="ReverseEnable" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="ReverseEnable">
		<xs:complexType>
		<xs:sequence>
			<xs:element ref="SystemID" minOccurs="1" maxOccurs="1" />
			<xs:choice maxOccurs="1" minOccurs="1">
				<xs:element ref="MDN" />
				<xs:element ref="IMSI" />
			</xs:choice>
<xs:element ref="Password" minOccurs="0" maxOccurs="1" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:simpleType name="MDNType">
		<xs:restriction base="xs:string">
			<xs:length value="11" />
			<xs:pattern value="13[0|1|3]\d{8}" />
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="MDN" type="MDNType"></xs:element>
	<xs:simpleType name="IMSIType">
		<xs:restriction base="xs:string">
			<xs:length value="15" />
			<xs:pattern value="\d*" />
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="IMSI" type="IMSIType"></xs:element>
	<xs:simpleType name="SystemIDType">
		<xs:restriction base="xs:string">
			<xs:length value="3" />
			<xs:pattern value="\d{3}" />
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="SystemID" type="SystemIDType"></xs:element>
	<xs:simpleType name="PasswordType">
		<xs:restriction base="xs:string">
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="Password" type="PasswordType"></xs:element>
</xs:schema>
,and a xml file:
<?xml version="1.0" encoding="utf-8"?>
<U-MAX>
    <ReverseEnable>
	<SystemID>906</SystemID>
        <MDN>13012345678</MDN>
        <Password>E9r!399Tsso00ua</Password>
    </ReverseEnable>
</U-MAX>
,when I parse it in my program as this:
File bookFile = null;
    UMAXDocument max = null;
    UMAXDocument.UMAX umax = null;
    ReverseEnableDocument.ReverseEnable rs = null;
    PasswordDocument pd = null;

    try
    {
        bookFile = new File("c:\\max.xml");
        XmlObject x = XmlLoader.load(bookFile);
        max = (UMAXDocument)XmlLoader.load(bookFile);
        umax = max.getUMAX();
        rs = umax.getReverseEnable();
        String password = rs.getPassword();
        String mdn = rs.getMDN();
        System.out.println("password="+password+";mdn"+mdn);
    }
it throw a java.lang.ClasssCastException,can you help me?
Thank you very much!

	
 				

        luke
        gqlu@hurray.com.cn
          2003-10-22




- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/