Hi,
I've no intimate knowledge about the xml/xsd spec - but in "normal" ll(k)
parsing, you would have to set a lookahead of three to solve this.
But I remember reading over a xml spec which said something about ambiguities
and that xml parsing usually involves only a lookahead of one.
E.g. in a dtd, such a construction is ambigious and can not be validated
properly:
<!element a (b*b)>
The reason is that the subrule b* gathers b's as long as these come - and
then fails to collect the required last one.
Your case is similar. So I don't think that you can bring castor to
speculative execution here or to introduce some lookup.
Why can't you just make one group with:
<element name="Name" type="string" />
<element name="Address" type="string" />
<element name="Zip" type="string" minOccurs="0"/>
Or, if you know what to expect, introduce a new tag that sourrounds the
responstypes, naming them.
Diez
Am Mittwoch, 26. Juni 2002 08:07 schrieb Perryn Fowler:
> I have an interesting problem:
>
> Say I had a schema containing some declarations like this:
>
> ....
> <element name="Response">
> <complexType>
> <sequence>
> <choice>
> <group ref="tns:ResponseTypeA" />
> <group ref="tns:ResponseTypeB" />
> </choice>
> </sequence>
> </complexType>
> </element>
> ....
>
> <group name="ResponseTypeA">
> <sequence>
> <element name="Name" type="string" />
> <element name="Address" type="string" />
> <element name="Zip" type="string" />
> </sequence>
> </group>
> ......
> <group name="ResponseTypeB">
> <sequence>
> <element name="Name" type="string" />
> <element name="Address" type="string" />
> </sequence>
> </group>
>
> I have run the SourceGenerator over it and now
> I have some XML like this which I am trying to unmarshal
> using the generated Response class.
>
> <Response>
> <Name>Billy</Name>
> <Address>Earth</Address>
> </Response>
>
>
> How can Castor figure out which type of group is represented here?
> Is it an invalid ResponseTypeA or a valid ResponseTypeB?
>
> It seems that Castor simply tries to fit it to the first response type in
> the list.
> If I execute code like
>
> Response r = (Response) Unmarshaller.unmarshal(file);
> r.getResponseTypeB();
>
> then the first line generates a validation error saying that Zip is
> required. If on the other
> hand I swap around the order of the group tags in the schema everything
> works fine.
>
> The thing is I know what sort of response I am expecting - Is there a way
> to tell Castor
> what group it should be looking for? Or perhaps to delay parsing of the XML
> inside the Response
> Tag until I call a getResponseTypeX() method? Any other way Castor could be
> used to solve this
> sort of problem?
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev