Title: A little guidance needed

I have an xsd file (ivr.xsd) as:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
        <xsd:element name="ivr">
                <xsd:complexType>
                        <xsd:choice>
                                <xsd:element ref="order_info_request" />
                        </xsd:choice>
                </xsd:complexType>
        </xsd:element>
        <xsd:element name="order_info_request">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element ref="user_id"/>
                                <xsd:element ref="store_num"/>
                                <xsd:element ref="order_num"/>
                        </xsd:sequence>
                <xsd:complexType>
        </xsd:element>
        <xsd:element name="order_num" type="xsd:decimal"/>
        <xsd:element name="store_num" type="xsd:short"/>
        <xsd:element name="user_id" type="xsd:string"/>
</xsd:schema>

I utilize SourceGenerator to create code required to handle the xml data.  I compile with
this simple main class:

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

public class myIvr {
        public static void main(String args[]) {
                try {
                        // -- read in the xml
                        Ivr ivr = (Ivr) Unmarshaller.unmarshal(Ivr.class, new
                      FileReader("order_info_request.xml"));

                        // -- marshal the changed ivr back to disk
                        FileWriter file = new FileWriter("ivr.xml");
                        Marshaller.marshal(ivr, file);
                        file.close();
                } catch (Exception e) {
                        System.out.println( e );
                }
        }
}

I can then run myIvr which reads in the order_info_request.xml and writes it back out
to ivr.xml.

order_info_request.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<ivr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\dumb\ivr.xsd">
        <order_info_request>
                <user_id>String</user_id>
                <store_num>999</store_num>
                <order_num>3.1415926535897932384626433832795</order_num>
        </order_info_request>
</ivr>

Now, I alter ivr.xsd as below, adding a second choice to the root element ( rx_info_request )
and the additional element rx_num and the description for rx_info_request.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
   <xsd:element name="ivr">
                <xsd:complexType>
                        <xsd:choice>
                                <xsd:element ref="order_info_request"/>
                                <xsd:element ref="rx_info_request"/>
                        </xsd:choice>
                </xsd:complexType>
   </xsd:element>
        <xsd:element name="order_info_request">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element ref="user_id"/>
                                <xsd:element ref="store_num"/>
                                <xsd:element ref="order_num"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
        <xsd:element name="rx_info_request">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element ref="user_id"/>
                                <xsd:element ref="store_num"/>
                                <xsd:element ref="rx_num"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
        <xsd:element name="order_num" type="xsd:decimal"/>
        <xsd:element name="rx_num" type="xsd:decimal"/>
        <xsd:element name="store_num" type="xsd:short"/>
        <xsd:element name="user_id" type="xsd:string"/>
</xsd:schema>

I run SourceGenerator on the schema, compile the classes, and attempt to run myIvr as before.
I get the following error:

$java myIvr
ValidationException: rx_info_request is a required field.;
   - location of error: XPATH: ivr{file: [not available]; line: 13; column: 7}

Why is this?  Isn't order_info_request.xml a valid xml document with regard to xsd.ivr?
What this appears to be 'saying' is that if I have a root element "ivr" that is a complex type
and it has 200 elements as choices, then to have a 'valid' document for only one of those
choices, I have to create a document that contains all choices.  Is this correct?


thanks,
reid

Reply via email to