Aleksei Valikov wrote:
> Hi.
>
>> Thanks for your reply.
>> I am forced to create all the mandatory children
>> because my XML will then become invalid. Moreover, I
>> get an exception when I try to marshal/unmarshal an
>> invalid XML.
>> JAXB need not guess the default values at all. Infact
>> all that I am doing right now is the following. To
>> create an element A which has B and C as mandatory
>> children:
>> ObjectFactory of = new ObjectFactory();
>> A a = of.newInstance(A.class);//0
>> B b = of.newInstance(B.class)//1
>> C c = of.newInstance(C.class)//2
>> A.setB(b);//3
>> A.setC(c);//4
>>
>> Cant JAXB do lines 1,2,3,4 automatically so that all I
>> need to do then is just line 0.
>>
>> Please also let me know if it is possible to
>> marshal/unmarshal an invalid xml incase I cant create
>> these mandatory children automatically.
>
>
> Actually seems like it is possible to marshal an invalid XML. It looks
> like a bug in current RI. See my next posting.
Marshalling does not include validation, it is an orthogonal operation
that the
user can choose to use or not, depending on their application, before
marshalling.
It is not a bug if one can marshal invalid XML.
Rationale on why validation is not mandatory part of
unmarshalling/marshalling
extracted from JAXB 1.0 specification Section 2.1.2 "Binding Framework".
> When the unmarshalling process incorporates validation and it successfully
> completes without any validation errors, both the input document and the
> resulting content tree are guaranteed to be valid. The marshalling
> process, on
> the other hand, does not actually perform validation. If only
> validated content
> trees are marshalled, this guarantees that generated XML documents are
> always
> valid with respect to the source schema.
>
> However, always requiring validation during unmarshalling and only
> allowing
> the marshalling of validated content trees proves to be too rigid and
> restrictive a
> requirement. Since existing XML parsers allow schema validation to be
> disabled, there exist a significant number of XML processing uses that
> disable
> schema validation to improve processing speed and/or to be able to process
> documents containing invalid or incomplete content. To enable the JAXB
> architecture to be used in these processing scenarios, the binding
> framework
> makes validation optional. How a JAXB technology implementation handles
> unmarshalling of an invalid document when validation is disabled is
> implementation-specific. The same holds true for marshalling an
> invalid content
> tree. It is expected that once an implementation is aware that it cannot
> unambiguously complete unmarshalling or marshalling, it will terminate
> processing with an exception.
-Joe
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net