xml - JAXB minOccurs and UnmarshalException -


i generated classes using xjc, , trying process following xml doc. getting error:

javax.xml.bind.unmarshalexception: unexpected end of element {http://schemas.xmlsoap.org/soap/envelope/}:body 

i believe because xml not contain fault element (when add in fault element, process without errors. response either contain retrieval_id or fault, never both. thought having minoccurs=0 in schema fix this, no go (at least how did it). possible use jaxb situation, is, when either of these elements may exist, never both @ same time?

xml response in question:

<?xml version = '1.0' encoding = 'utf-8'?> <env:envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/xmlschema-instance" xmlns:xsd="http://www.w3.org/1999/xmlschema"> <env:header>   <bmw:rule xmlns:bmw="http://adr.com/bmw">      <bmw:customer>44</bmw:customer>      <bmw:schemaname>abc</bmw:schemaname>      <bmw:schemaversion>1.0</bmw:schemaversion>   </bmw:rule> </env:header> <env:body>   <bmw:retrieval_id xmlns:bmw="http://adr.com/bbs">15086</bmw:retrieval_id> </env:body> </env:envelope> 

schema:

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified" targetnamespace="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bmw="http://adr.com/bmw"> <xs:import namespace="http://adr.com/bmw" schemalocation="bmw.xsd"/> <xs:element name="envelope"> <xs:complextype>   <xs:sequence>     <xs:element ref="env:header"/>     <xs:element ref="env:body"/>   </xs:sequence> </xs:complextype> </xs:element> <xs:element name="header"> <xs:complextype>   <xs:sequence>     <xs:element ref="bmw:rule"/>   </xs:sequence> </xs:complextype> </xs:element> <xs:element name="body"> <xs:complextype>   <xs:sequence>     <xs:element ref="bmw:retrieval_id" minoccurs="0"/>     <xs:element ref="env:fault" minoccurs="0"/>   </xs:sequence>  </xs:complextype> </xs:element> <xs:element name="fault"> <xs:complextype>   <xs:sequence>     <xs:element ref="bmw:fault"/>   </xs:sequence>  </xs:complextype> </xs:element> </xs:schema> 

right complextype contains:

<xs:complextype>   <xs:sequence>     <xs:element ref="bmw:retrieval_id" minoccurs="0"/>     <xs:element ref="env:fault" minoccurs="0"/>   </xs:sequence>  </xs:complextype> 

if 1 appears @ given time, want xs:choice instead of xs:sequence. see this more.

<xs:complextype>   <xs:choice>     <xs:element ref="bmw:retrieval_id" minoccurs="0"/>     <xs:element ref="env:fault" minoccurs="0"/>   </xs:choice>  </xs:complextype> 

you need regenerate class files using xjc after changing schema change reflected in java.

this article oracle has small section on how jaxb handles choice. this blog post has comprehensive example of choice , jaxb. important thing note have:

@xmlelements(value = {             @xmlelement(name="retrieval_id",                         type=retrievalid.class),             @xmlelement(name="fault",                         type=fault.class)     }) object possiblevalue; 

in java.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -