History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CASTOR-2132
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Werner Guttmann
Reporter: Christophe Delory
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
castor

Unmarshalling the same element from 2 different namespaces

Created: 30/Aug/07 11:33 AM   Updated: 14/Mar/08 06:41 AM
Component/s: XML
Affects Version/s: 1.1.2.1
Fix Version/s: 1.2

Time Tracking:
Original Estimate: Not Specified
Remaining Estimate: 0 minutes
Time Spent - 1 hour, 15 minutes
Time Spent: 1 hour, 15 minutes
Time Spent - 1 hour, 15 minutes

File Attachments: 1. Zip Archive castor-namespaces.zip (1 kb)
2. Text File patch.c2132.20080108.txt (2 kb)
3. Text File patch.c2132.2080109.txt (2 kb)
4. XML File videofeed.xml (58 kb)



 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Werner Guttmann - 01/Sep/07 04:23 AM
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 .. .

Werner Guttmann - 07/Jan/08 05:42 PM
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 ?

Werner Guttmann - 08/Jan/08 03:56 PM
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.


Werner Guttmann - 08/Jan/08 05:08 PM
Initial patch for review. Unfortunately, post-patch there's two CTF tests failing on XML diffs.

Werner Guttmann - 08/Jan/08 05:32 PM
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.

Christophe Delory - 09/Jan/08 03:02 AM
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.

Werner Guttmann - 09/Jan/08 07:24 AM
Hmm .. can you attach a complete sample of what you are receiving ?

Christophe Delory - 09/Jan/08 09:50 AM
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.

Werner Guttmann - 09/Jan/08 05:27 PM
Sometimes I wonder whether it will happen that somebody is willing to acknowledge one's private efforts financially ... ;-(.

Werner Guttmann - 09/Jan/08 05:31 PM
Final patch for review.