Hi, I don't know if this is the right place to post this question, pls let me
know if it's not. (And I'd apprecciate you tell me where is the right place ;))

  This is the problem: when tried to unmarshall from a simple XML file, I call
the getXXX method and all I get is null. I can't figured out what I'm doing
wrong... Any ideas?

  I pasted the generated files, tried to keep them as simple as possible.

  TIA.

  This is the Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">
        <xsd:element name="root">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element name="Element1" type="xsd:string"/>
                                <xsd:element name="Element2" type="xsd:string"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
</xsd:schema>


  This is the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="C:\test1.xsd">
        <Element1>Elem1</Element1>
        <Element2>Elem2</Element2>
</root>

  This is my Test Java class:

import java.io.*;
import org.exolab.castor.xml.*;
import org.exolab.castor.xml.*;

public class Test {

  public Test() {
    Root root = new Root();
    try {
      root.unmarshal(new FileReader("C:\\test1.xml"));
    }
    catch (FileNotFoundException ex) {
    }catch (ValidationException ex) {
    }catch (MarshalException ex) {
    }
  }
  public static void main(String[] args) {
    Test test1 = new Test();
  }
}

  This is the Generated Java file by Castor:

/*
 * This class was automatically generated with 
 * <a href="http://castor.exolab.org";>Castor 0.9.3</a>, using an
 * XML Schema.
 * $Id$
 */

package mysite;

  //---------------------------------/
 //- Imported classes and packages -/
//---------------------------------/

import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import org.exolab.castor.xml.*;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.DocumentHandler;

/**
 * 
 * @version $Revision$ $Date$
**/
public class Root implements java.io.Serializable {


      //--------------------------/
     //- Class/Member Variables -/
    //--------------------------/

    private java.lang.String _element1;

    private java.lang.String _element2;


      //----------------/
     //- Constructors -/
    //----------------/

    public Root() {
        super();
    } //-- mysite.Root()


      //-----------/
     //- Methods -/
    //-----------/

    /**
    **/
    public java.lang.String getElement1()
    {
        return this._element1;
    } //-- java.lang.String getElement1() 

    /**
    **/
    public java.lang.String getElement2()
    {
        return this._element2;
    } //-- java.lang.String getElement2() 

    /**
    **/
    public boolean isValid()
    {
        try {
            validate();
        }
        catch (org.exolab.castor.xml.ValidationException vex) {
            return false;
        }
        return true;
    } //-- boolean isValid() 

    /**
     * 
     * @param out
    **/
    public void marshal(java.io.Writer out)
        throws org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException
    {
        
        Marshaller.marshal(this, out);
    } //-- void marshal(java.io.Writer) 

    /**
     * 
     * @param handler
    **/
    public void marshal(org.xml.sax.DocumentHandler handler)
        throws org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException
    {
        
        Marshaller.marshal(this, handler);
    } //-- void marshal(org.xml.sax.DocumentHandler) 

    /**
     * 
     * @param element1
    **/
    public void setElement1(java.lang.String element1)
    {
        this._element1 = element1;
    } //-- void setElement1(java.lang.String) 

    /**
     * 
     * @param element2
    **/
    public void setElement2(java.lang.String element2)
    {
        this._element2 = element2;
    } //-- void setElement2(java.lang.String) 

    /**
     * 
     * @param reader
    **/
    public static mysite.Root unmarshal(java.io.Reader reader)
        throws org.exolab.castor.xml.MarshalException,
org.exolab.castor.xml.ValidationException
    {
        return (mysite.Root) Unmarshaller.unmarshal(mysite.Root.class, reader);
    } //-- mysite.Root unmarshal(java.io.Reader) 

    /**
    **/
    public void validate()
        throws org.exolab.castor.xml.ValidationException
    {
        org.exolab.castor.xml.Validator validator = new
org.exolab.castor.xml.Validator();
        validator.validate(this);
    } //-- void validate() 

}

  This is the Descriptor file:

/*
 * This class was automatically generated with 
 * <a href="http://castor.exolab.org";>Castor 0.9.3</a>, using an
 * XML Schema.
 * $Id$
 */

package mysite;

  //---------------------------------/
 //- Imported classes and packages -/
//---------------------------------/

import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.xml.*;
import org.exolab.castor.xml.FieldValidator;
import org.exolab.castor.xml.TypeValidator;
import org.exolab.castor.xml.XMLFieldDescriptor;
import org.exolab.castor.xml.handlers.*;
import org.exolab.castor.xml.util.XMLFieldDescriptorImpl;
import org.exolab.castor.xml.validators.*;

/**
 * 
 * @version $Revision$ $Date$
**/
public class RootDescriptor extends
org.exolab.castor.xml.util.XMLClassDescriptorImpl {


      //--------------------------/
     //- Class/Member Variables -/
    //--------------------------/

    private java.lang.String nsPrefix;

    private java.lang.String nsURI;

    private java.lang.String xmlName;

    private org.exolab.castor.xml.XMLFieldDescriptor identity;


      //----------------/
     //- Constructors -/
    //----------------/

    public RootDescriptor() {
        super();
        xmlName = "root";
        XMLFieldDescriptorImpl  desc           = null;
        XMLFieldHandler         handler        = null;
        FieldValidator          fieldValidator = null;
        
        //-- set grouping compositor
        setCompositorAsSequence();
        //-- initialize attribute descriptors
        
        //-- initialize element descriptors
        
        //-- _element1
        desc = new XMLFieldDescriptorImpl(java.lang.String.class, "_element1",
"Element1", NodeType.Element);
        desc.setImmutable(true);
        handler = (new XMLFieldHandler() {
            public Object getValue( Object object ) 
                throws IllegalStateException
            {
                Root target = (Root) object;
                return target.getElement1();
            }
            public void setValue( Object object, Object value) 
                throws IllegalStateException, IllegalArgumentException
            {
                try {
                    Root target = (Root) object;
                    target.setElement1( (java.lang.String) value);
                }
                catch (Exception ex) {
                    throw new IllegalStateException(ex.toString());
                }
            }
            public Object newInstance( Object parent ) {
                return null;
            }
        } );
        desc.setHandler(handler);
        desc.setRequired(true);
        desc.setMultivalued(false);
        addFieldDescriptor(desc);
        
        //-- validation code for: _element1
        fieldValidator = new FieldValidator();
        fieldValidator.setMinOccurs(1);
        { //-- local scope
            StringValidator sv = new StringValidator();
            sv.setWhiteSpace("preserve");
            fieldValidator.setValidator(sv);
        }
        desc.setValidator(fieldValidator);
        
        //-- _element2
        desc = new XMLFieldDescriptorImpl(java.lang.String.class, "_element2",
"Element2", NodeType.Element);
        desc.setImmutable(true);
        handler = (new XMLFieldHandler() {
            public Object getValue( Object object ) 
                throws IllegalStateException
            {
                Root target = (Root) object;
                return target.getElement2();
            }
            public void setValue( Object object, Object value) 
                throws IllegalStateException, IllegalArgumentException
            {
                try {
                    Root target = (Root) object;
                    target.setElement2( (java.lang.String) value);
                }
                catch (Exception ex) {
                    throw new IllegalStateException(ex.toString());
                }
            }
            public Object newInstance( Object parent ) {
                return null;
            }
        } );
        desc.setHandler(handler);
        desc.setRequired(true);
        desc.setMultivalued(false);
        addFieldDescriptor(desc);
        
        //-- validation code for: _element2
        fieldValidator = new FieldValidator();
        fieldValidator.setMinOccurs(1);
        { //-- local scope
            StringValidator sv = new StringValidator();
            sv.setWhiteSpace("preserve");
            fieldValidator.setValidator(sv);
        }
        desc.setValidator(fieldValidator);
        
    } //-- mysite.RootDescriptor()


      //-----------/
     //- Methods -/
    //-----------/

    /**
    **/
    public org.exolab.castor.mapping.AccessMode getAccessMode()
    {
        return null;
    } //-- org.exolab.castor.mapping.AccessMode getAccessMode() 

    /**
    **/
    public org.exolab.castor.mapping.ClassDescriptor getExtends()
    {
        return null;
    } //-- org.exolab.castor.mapping.ClassDescriptor getExtends() 

    /**
    **/
    public org.exolab.castor.mapping.FieldDescriptor getIdentity()
    {
        return identity;
    } //-- org.exolab.castor.mapping.FieldDescriptor getIdentity() 

    /**
    **/
    public java.lang.Class getJavaClass()
    {
        return mysite.Root.class;
    } //-- java.lang.Class getJavaClass() 

    /**
    **/
    public java.lang.String getNameSpacePrefix()
    {
        return nsPrefix;
    } //-- java.lang.String getNameSpacePrefix() 

    /**
    **/
    public java.lang.String getNameSpaceURI()
    {
        return nsURI;
    } //-- java.lang.String getNameSpaceURI() 

    /**
    **/
    public org.exolab.castor.xml.TypeValidator getValidator()
    {
        return this;
    } //-- org.exolab.castor.xml.TypeValidator getValidator() 

    /**
    **/
    public java.lang.String getXMLName()
    {
        return xmlName;
    } //-- java.lang.String getXMLName() 

}

-----------------------------------------------
�����, ���������� �������� ������� XEROX PHASER
3210!http://r.mail.ru/cln1895/www.megashop.ru/index.php?secr=6&pid=1142877

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to