Hi,

Sorry to bother you with this. It seems like this is
something simple, and
I must be missing something in the documentation.

I'm evaluating Castor to determine if it can be used
to help us convert our
XML schemas into our Java Object Model and vice versa.
 Our XML schema does
not match our object model.  I have been trying to use
the mapping file to
make a simple example to work.

Here is the Schema:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.4 U
(http://www.xmlspy.com) by Vertex Inc
(Vertex Inc) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault
="qualified" attributeFormDefault="unqualified">
  <xs:element name="MyNeighborhood">
    <xs:annotation>
      <xs:documentation>Comment describing your root
element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Development">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="House">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Number"/>
                    <xs:element name="Street"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Here are the java classes I created:

public class Neighborhood {
  public Neighborhood() {
  }

  private Development development = new Development();
  private House house = new House();

  public Development getDevelopment() {
    return this.development;
  }

  public void setDevelopment(Development development)
{
    this.development = development;
  }

  public House getHouse() {
    return this.house;
  }

  public void setHouse(House house) {
    this.house = house;
  }
}


public class Development {
  public Development() {
  }
}


public class House {
  public House() {
  }

  private String number;
  private String street;

  public String getNumber() {
    return number;
  }

  public void setNumber(String number) {
    this.number = number;
  }

  public String getStreet() {
    return street;
  }

  public void setStreet(String street) {
    this.street = street;
  }
}


Here is the main program:

import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;

import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.Marshaller;

import java.io.IOException;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.FileWriter;

import org.xml.sax.InputSource;

public class main {

  public static void main(String args[]) {

    Mapping mapping = new Mapping();

    try {
      // 1. Load the mapping information from the file
      mapping.loadMapping( "mapping.xml" );

      // 2. Unmarshal the data
      Unmarshaller unmar = new Unmarshaller(mapping);
      unmar.setLogWriter(new PrintWriter(new
FileWriter("out.log")));
      unmar.setDebug(true);
      //unmar.setIgnoreExtraElements(true);
      Neighborhood n =
(Neighborhood)unmar.unmarshal(new InputSource(new
FileReader("neighborhood.xml")));

      // 3. Do some processing on the data
      String number = n.getHouse().getNumber();
      System.out.println("Number = " + number);

      String street = n.getHouse().getStreet();
      System.out.println("Street = " + street);

      // 4. marshal the data with the total price back
and print the XML in
the console
      Marshaller marshaller = new Marshaller(new
OutputStreamWriter(System.out));
      marshaller.setMapping(mapping);
      marshaller.marshal(n);

    } catch (Exception e) {
      System.out.println(e);
      return;
    }
  }
}

And here is the mapping file:
<?xml version="1.0" encoding="UTF-8"?>
  <mapping xmlns="http://castor.exolab.org/"; xmlns:cst
="http://castor.exolab.org/";>
  <description>Castor generated mapping
file</description>

  <class cst:name="House" cst:access="shared">
    <description>Default mapping for class
House</description>
    <map-to cst:xml="house"/>
    <field cst:name="number"
cst:type="java.lang.String">
      <bind-xml name="number" node="element"/>
    </field>
    <field cst:name="street"
cst:type="java.lang.String">
      <bind-xml name="street" node="element"/>
    </field>
  </class>

  <class cst:name="Development" cst:access="shared">
    <description>Default mapping for class
Development</description>
  </class>

  <class cst:name="Neighborhood" cst:access="shared">
    <description>Default mapping for class
Neighborhood</description>
    <map-to cst:xml="MyNeighborhood"/>
    <field cst:name="house" cst:type="House">
      <bind-xml name="house" node="element"/>
    </field>
    <field cst:name="development"
cst:type="Development">
      <bind-xml name="development" node="element"/>
    </field>
  </class>

</mapping>


I get the following error when I run main:
org.xml.sax.SAXException: unable to find
FieldDescriptor for 'house' in
ClassDescriptor of development{file: [not available];
line: 5; column: 12}

This is just a simple example I created to try to
re-create a larger issue
we have here, withour object model differing from our
XML schema to see if
I think Castor can help solve our problem.

Thanks for taking the time to read this, and for
providing me with any
suggestions you may have.

-Mike

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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

Reply via email to