Hi all,

I am getting the following exception when trying to UnMarshall an xml
file. The file gets validated properly in XMLSpy with the schema. 

Am I missing something ?

Any help is highly appreciated.

thanks,
Saravanan

Exception=========================================


org.xml.sax.SAXException: unable to find FieldDescriptor for 'book' in
ClassDescriptor of order        at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.ja
va:1791)        at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.ja
va:1292)        at
org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(
Unknown Source) at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDi
spatcher.dispatch(Unknown Source)       at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkn
own Source)     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:605)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:513)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:691)
        at Order.unmarshal(Order.java:91)
        at ProcessOrder.main(ProcessOrder.java:16)



XSD===========================================================

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.bookstore.org/bookstore-schema";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns="http://www.bookstore.org/bookstore-schema";
elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xsd:element name="bookstore">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="book" type="BookType" minOccurs="0"
maxOccurs="unbounded"/>
        <xsd:element name="order" type="OrderType" minOccurs="0"
maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:key name="book-pk">
      <xsd:selector xpath="book"/>
      <xsd:field xpath="ISDN"/>
    </xsd:key>
    <xsd:keyref name="book-ref" refer="book-pk">
      <xsd:selector xpath="order/book-ref"/>
      <xsd:field xpath="@ISDN"/>
    </xsd:keyref>
  </xsd:element>
  <xsd:complexType name="BookType">
    <xsd:sequence>
      <xsd:element name="ISDN" type="xsd:string"/>
      <xsd:element name="title" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="OrderType">
    <xsd:sequence>
      <xsd:element name="order-number" type="xsd:string"/>
      <xsd:element name="book-ref" minOccurs="0" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:attribute name="ISDN" type="xsd:string"/>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>


XML ============================================================

<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns="http://www.bookstore.org/bookstore-schema";>
  <book>
    <ISDN>1234</ISDN>
    <title>Rockclimbing</title>
  </book>
  <book>
    <ISDN>5678</ISDN>
    <title>Advanced Rockclimbing</title>
  </book>
  <order>
    <order-number>1000</order-number>
    <book-ref ISDN="1234"/>
    <book-ref ISDN="5678"/>
  </order>
</bookstore>




ProcessOrder.java=======================================

import java.util.*;
import java.io.*;

import org.exolab.castor.mapping.*;
import org.exolab.castor.types.*;
import org.exolab.castor.xml.*;

public class ProcessOrder {
    public static void main(String args[])  {
        try {
            String filename = "order.xml";
            if(args != null && args.length > 0 ) {
                filename = args[0];
            }
            Reader reader = new FileReader( filename );
            Order order = (Order) Order.unmarshal(reader);

            printOrder(order);
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }

    private static void printOrder ( Order o) {
        System.out.println("Order Number = " + o.getOrderNumber());
        for(Enumeration e = o.enumerateBookRef(); e.hasMoreElements(); )
{            BookRef br = (BookRef) e.nextElement();
            System.out.println("Book ref = " + br.getISDN());
        }
    }
}


==========================================================





-- 
Saravanan Subbiah



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

Reply via email to