I've gotten Castor to marshall in conformance with my Schema, but now I
find it's unable to unmarshall the XML it has just produced. Perhaps
this is trivial to fix, but I'm a newbie at Castor so it isn't obvious
to me from the exception text. 

Detailed desciption follows...

Thanks, 
// Ben



Failure to Unmarshall
---------------------

When attempting to unmarshall from the XML above, we get an exception
from deep within the bowels of Castor.

  "unable to find FieldDescriptor for 'JuristischePerson' in
  ClassDescriptor of Klaeger"

It is refering to the following tag::

  <p:JuristischePerson xmlns:p="ns:person" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
     xsi:type="p:JuristischePerson">

There is no ClassDescriptor for Klaeger, because Klaeger doesn't
correspond to a class, it's just a level of nesting established by a
``bind-xml/@location``.


The Mapping File
----------------

The following mapping produces the XML I desire (along with some
extraneous ``xsi:type`` elements.)

::

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE mapping PUBLIC 
            "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" 
            "http://www.castor.org/mapping.dtd"; >
  <m:mapping 
     xmlns:m="http://castor.exolab.org/"; xmlns:f="ns:fall"
xmlns:p="ns:person"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    
    <m:class name="dataobj.Fall" >
      <!-- ***
       * the 'identity' of Fall is aktenzeichen, but 
       * we can't delcare it because that forces it 
       * to be the last element 
       *** -->
      <m:map-to  ns-uri="ns:fall" xml="Fall"/>
      <m:field name="aktenzeichen" type="string">
        <m:bind-xml name="Aktenzeichen" node="element"/>
      </m:field>
      <m:field name="klaeger" type="dataobj.Person">
        <m:bind-xml location="Klaeger" xmlns="ns:fall"
                    auto-naming="deriveByClass"/>
        <!-- ***
         * by setting the default namespace we get 
         * Klaeger to be of that namespace 
         *** -->
      </m:field>
      <m:field name="angeklagter" type="dataobj.Person">
        <m:bind-xml location="Beklagter" auto-naming="deriveByClass"
xmlns="ns:fall"/>
      </m:field>
      <m:field name="sonstige" collection="collection"
type="dataobj.Person">
        <m:bind-xml auto-naming="deriveByClass"/>
      </m:field>
    </m:class>
    
    <m:class name="dataobj.Person" identity="idNumber">
      <m:field name="idNumber" type="integer">
        <m:bind-xml name="p:idNumber" node="element"/>
      </m:field>
    </m:class>
    
    <m:class name="dataobj.JuristischePerson" 
             extends="dataobj.Person">
      <m:map-to  xml="JuristischePerson"
                 ns-prefix="p" ns-uri="ns:person" />
      <!-- ns-prefix is nice, but not necessary -->
      <m:field name="bezeichnung" type="string">
        <m:bind-xml name="p:Bezeichnung"/>
      </m:field>
    </m:class> 
    
    <m:class name="dataobj.NatuerlichePerson" 
             extends="dataobj.Person">
      <m:map-to xml="NatuerlichePerson"
                ns-prefix="p" ns-uri="ns:person"/>
      <m:field name="vorname" type="string">
        <m:bind-xml name="p:Vorname" node="element"/>
      </m:field>
      <m:field name="nachname" type="string">
        <m:bind-xml name="p:Nachname" node="element"/>
      </m:field>
    </m:class>
    
  </m:mapping>
  
  
1. ``map-to`` and ``bind-xml`` use different methods for specifying
   the namespace of the XML element.  Be aware of this.

   - ``map-to`` uses the attribute ``ns-uri`` to specify the URI of
     the namespace to be used.

   - ``bind-xml`` uses a QName in ``name``. The prefix used in the
     QName must be declared as an XML namespace in the mapping file.

2. ``bind-xml/@location`` does not accept a QName. We can, however,
   "trick" it by redefining the default namespace at that node using
   ``xmlns``::

      <m:field name="klaeger" type="dataobj.Person">
        <m:bind-xml location="Klaeger" 
                    auto-naming="deriveByClass"
                    xmlns="ns:fall" />
        <!-- ***
         * by setting the default namespace to ns:fall we get
         * Klaeger to be of that NS 
         *** -->
      </m:field>

3. Declaring ``aktenzeichen`` as the ``identity`` of ``Fall`` forces
   it to be the last child element, despite the fact that it's
   declared first. Don't do this::

      <m:class name="dataobj.Fall" identity="aktenzeichen">
        <m:map-to  ns-uri="ns:fall" xml="Fall"/>
        <m:field name="aktenzeichen" type="string">
          <m:bind-xml name="Aktenzeichen" node="element"/>
        </m:field>
    
Resulting XML
-------------

This XML conforms to my expectations, with the exception of the
extraneous ``xsi:type`` elements.

**HOWEVER** Castor is unable to unmarshall from this representation.

::

  <Fall xmlns="ns:fall">
    <Aktenzeichen>2006-1123114-X</Aktenzeichen>
    <Klaeger>
      <p:JuristischePerson xmlns:p="ns:person"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
         xsi:type="p:JuristischePerson">
        <p:idNumber>2</p:idNumber>
        <p:Bezeichnung>Acme Motor Co</p:Bezeichnung>
      </p:JuristischePerson>
    </Klaeger>
    <Beklagter>
      <p:NatuerlichePerson xmlns:p="ns:person"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
         xsi:type="p:NatuerlichePerson">
        <p:idNumber>1</p:idNumber>
        <p:Vorname>Baltimore</p:Vorname>
        <p:Nachname>Tilly</p:Nachname>
      </p:NatuerlichePerson>
    </Beklagter>
    <p:NatuerlichePerson xmlns:p="ns:person" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xsi:type="p:NatuerlichePerson">
      <p:idNumber>3</p:idNumber>
      <p:Vorname>Bird</p:Vorname>
      <p:Nachname>Tweety</p:Nachname>
    </p:NatuerlichePerson>
    <p:NatuerlichePerson xmlns:p="ns:person" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xsi:type="p:NatuerlichePerson">
      <p:idNumber>4</p:idNumber>
      <p:Vorname>Banner</p:Vorname>
      <p:Nachname>David</p:Nachname>
    </p:NatuerlichePerson>
  </Fall>


-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to