castor

Unmarshalling the same element from 2 different namespaces

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1.2.1
  • Fix Version/s: 1.2
  • Component/s: XML
  • Labels:
    None
  • Number of attachments :
    4

Description

I get a "MarshalException: element "description" occurs more than once" when trying to unmarshal the following (apparently valid) XML fragment:
<item>
<description>One description</description>
<media:description>Another desc</media:description>
</item>

Attached is one Java class, the mapping file & the XML sample as a single zip file.
In order to run the test, add the following jars in the same directory: castor-1.1.2.1.jar, commons-logging.jar, xerces.jar.

You also may try to change the two fields declaration order in mapping.xml, and get another exception: "MarshalException: unable to find FieldDescriptor for 'description' in ClassDescriptor of item{File: ; line: 4; column: 21}"

Hope it will help.

  1. patch.c2132.20080108.txt
    08/Jan/08 5:08 PM
    2 kB
    Werner Guttmann
  2. patch.c2132.2080109.txt
    09/Jan/08 5:31 PM
    2 kB
    Werner Guttmann
  3. videofeed.xml
    09/Jan/08 9:50 AM
    58 kB
    Christophe Delory

Activity

Hide
Werner Guttmann added a comment -

I can confirm that I am getting the very same exceptions. I have tried to modify the given XML document instance to use an explicit namespace declaration as well as a default namespace declarations to qualify the remainder of the document - which does not change anything .. .

Show
Werner Guttmann added a comment - I can confirm that I am getting the very same exceptions. I have tried to modify the given XML document instance to use an explicit namespace declaration as well as a default namespace declarations to qualify the remainder of the document - which does not change anything .. .
Hide
Werner Guttmann added a comment -

Christophe, I have recently made some code changes in this area, that originated from a bug with the XML code generator. As part of this, I have changed some code areas that deal with XML namespaces as well. Would you be in a position to retry against the 1.2 snapshot release I just made available ?

Show
Werner Guttmann added a comment - Christophe, I have recently made some code changes in this area, that originated from a bug with the XML code generator. As part of this, I have changed some code areas that deal with XML namespaces as well. Would you be in a position to retry against the 1.2 snapshot release I just made available ?
Hide
Werner Guttmann added a comment -

Christophe, changing your input XML to

<?xml version="1.0"?>
<def:item xmlns:def="default" xmlns:media="http://search.yahoo.com/mrss/">
	<def:description>My description field</def:description>
	<media:description>My media description field</media:description>
</def:item>

and the mapping file to

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN" "http://castor.exolab.org/mapping.dtd">
<mapping xmlns:def="default" xmlns:media="http://search.yahoo.com/mrss/">
    <class name="xml.c2132.Item">
        <map-to xml="item" />
        <field name="mediaDescription" type="string" get-method="getMediaDescription"
            set-method="setMediaDescription">
            <bind-xml name="media:description" node="element" />
        </field>
        <field name="description" type="string" get-method="getDescription"
            set-method="setDescription">
            <bind-xml name="def:description" node="element" />
        </field>
    </class>
</mapping>

I can get things to work fully. It looks like there's a problem with the use of default XML namespaces in this context.

Show
Werner Guttmann added a comment - Christophe, changing your input XML to
<?xml version="1.0"?>
<def:item xmlns:def="default" xmlns:media="http://search.yahoo.com/mrss/">
	<def:description>My description field</def:description>
	<media:description>My media description field</media:description>
</def:item>
and the mapping file to
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN" "http://castor.exolab.org/mapping.dtd">
<mapping xmlns:def="default" xmlns:media="http://search.yahoo.com/mrss/">
    <class name="xml.c2132.Item">
        <map-to xml="item" />
        <field name="mediaDescription" type="string" get-method="getMediaDescription"
            set-method="setMediaDescription">
            <bind-xml name="media:description" node="element" />
        </field>
        <field name="description" type="string" get-method="getDescription"
            set-method="setDescription">
            <bind-xml name="def:description" node="element" />
        </field>
    </class>
</mapping>
I can get things to work fully. It looks like there's a problem with the use of default XML namespaces in this context.
Hide
Werner Guttmann added a comment -

Initial patch for review. Unfortunately, post-patch there's two CTF tests failing on XML diffs.

Show
Werner Guttmann added a comment - Initial patch for review. Unfortunately, post-patch there's two CTF tests failing on XML diffs.
Hide
Werner Guttmann added a comment -

Btw, I am not sure about the validity of your XML, as you are missing a default namespace declaration. But adding such a definition does not change the fact that there's a problem.

Show
Werner Guttmann added a comment - Btw, I am not sure about the validity of your XML, as you are missing a default namespace declaration. But adding such a definition does not change the fact that there's a problem.
Hide
Christophe Delory added a comment -

Werner, thanks a lot for your support.
There is no way for me to change the input XML: it's an external RSS feed (in turn, MediaRSS).
Currently I can work around the Castor issue, but of course I will be very pleased when you will fix it definitely.
I stay in touch.

Show
Christophe Delory added a comment - Werner, thanks a lot for your support. There is no way for me to change the input XML: it's an external RSS feed (in turn, MediaRSS). Currently I can work around the Castor issue, but of course I will be very pleased when you will fix it definitely. I stay in touch.
Hide
Werner Guttmann added a comment -

Hmm .. can you attach a complete sample of what you are receiving ?

Show
Werner Guttmann added a comment - Hmm .. can you attach a complete sample of what you are receiving ?
Hide
Christophe Delory added a comment -

I've attached a full XML sample of what should be unmarshalled.
The case where for example a 'title" element coexist with a 'media:title' element under the same parent, doesn't occur here hopefully.
It may occur according to the MediaRSS spec (http://search.yahoo.com/mrss).
Hope it'll help.

Show
Christophe Delory added a comment - I've attached a full XML sample of what should be unmarshalled. The case where for example a 'title" element coexist with a 'media:title' element under the same parent, doesn't occur here hopefully. It may occur according to the MediaRSS spec (http://search.yahoo.com/mrss). Hope it'll help.
Hide
Werner Guttmann added a comment -

Sometimes I wonder whether it will happen that somebody is willing to acknowledge one's private efforts financially ... ;-(.

Show
Werner Guttmann added a comment - Sometimes I wonder whether it will happen that somebody is willing to acknowledge one's private efforts financially ... ;-(.
Hide
Werner Guttmann added a comment -

Final patch for review.

Show
Werner Guttmann added a comment - Final patch for review.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
0m
Remaining Estimate - 0 minutes
Logged:
1h 15m
Time Spent - 1 hour, 15 minutes