users@jaxb.java.net

Re: Elements following unexpected elements are ignored

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Tue, 06 Dec 2005 10:02:16 -0800

If new elements were added at the end, this would have worked.

Gregor Koukkoullis wrote:
> Hi...
>
> I tried to use
> <xsd:any maxOccurs="unbounded" processContents="skip" namespace="##any"/>
> Which causes a Unique Particle Attribution violation, which kind of makes
> sense.
> Then I tried
> <xsd:any maxOccurs="unbounded" processContents="skip" namespace="##other"/>
> But the results are the same as before without any.
>
> Here is a part of my schema:
> <xsd:complexType name="XJBFavoritesList">
> <xsd:sequence>
> <xsd:element maxOccurs="unbounded" minOccurs="0" name="favorite-host"
> type="XJBFavoriteHost" />
> </xsd:sequence>
> </xsd:complexType>
> <xsd:complexType name="XJBFavoriteHost">
> <xsd:sequence>
> <xsd:any maxOccurs="unbounded" processContents="skip"
> namespace="##other"/>
> <xsd:element minOccurs="0" name="host-name" type="xsd:string"/>
> <xsd:element minOccurs="0" name="ip" type="xsd:hexBinary"/>
> <xsd:element minOccurs="0" name="port" type="xsd:int"/>
> </xsd:sequence>
> </xsd:complexType>
>
> My XML:
> <favorites-list>
> <favorite-host>
> <blubber>asdf</blubber>
> <ip>ABCD1234</ip>
> <blubber>asdf</blubber>
> <port>6346</port>
> </favorite-host>
> </favorites-list>
>
> My ValidationEventHandler logs this output:
> 051115 14:17:38,562 DEBUG/phex.xml.XMLBuilder [main]:: Encountered
> validation event: Unexpected element {}:blubber 1
> 051115 14:17:51,711 DEBUG/phex.xml.XMLBuilder [main]:: Encountered
> validation event: Unexpected element {}:ip 1
> 051115 14:17:59,472 DEBUG/phex.xml.XMLBuilder [main]:: Encountered
> validation event: Unexpected element {}:port 1
> I always return true.
>
> All I want is that it ignores the <blubber> element and continues
> unmarshaling, without declaring the following elements as unexpected.
> I also tried to use <xsd:all> instead of <xsd:sequence> but with the same
> results.
>
> Gregor
>
>> On 15/11/05, Dmitri Colebatch <colebatchd_at_gmail.com> wrote:
>>
>> Hi Gregor,
>>
>> We have faced a similar situation, and I've simply added and <xsd:any
>> /> to my schema - jaxb seems to be happy with this, although it may
>> not be an option for you.
>>
>> cheers
>> dim
>>
>> On 15/11/05, Gregor Koukkoullis <kou_at_gmx.de> wrote:
>> > Hi...
>> >
>> > I'm a happy JAXB since a few years, and I have to thank the team for
>> this
>> > great work.
>> >
>> > Unfortunalty I came across a problem that I cant solve and I hope you
>> can
>> > help me to find a way to make it work. I'm using Java 1.4 and JAXB 1.0.4
>> > (also tried the build jaxb-ri-20051113).
>> >
>> > I like to read a XML file that contains elements I like to ignore. Main
>> > reason is that a newer version of the server software contains new
>> elements
>> > but older client versions dont understand them and should skip and
>> ignore
>> > these elements.
>> > I was always receiving a unexpected element error and parsing stopped. I
>> > searched this mailing list and read that I should implemented a
>> > ValidationEventHandler that returns true on handleEvent() for this
>> error. I
>> > did this.
>> > The result is that this element gets now ignored and parsing continues
>> > (YES!) but all the following valid and known elements on the same level
>> also
>> > get ignored and are called to be unexpected (oh no..).
>> >
>> > Is there any way I can get it to work to just skip the unknown elements
>> and
>> > cleanly continue parsing the following known elements.
>> >
>> > Thanks,
>> > Gregor
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com