An attribute and element share the same name in my XSD. Now what?

0
I have been given a third party XSD to use for mapping XML to objects. In that XSD one of the attributes of the root object shares the same name as one of the root's elements. Here's a simplified version: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="sync_book"> <xs:sequence> <xs:element name="title" type="String"/> <xs:element name="author" type="String"/> </xs:sequence> </xs:complexType> <xs:complexType name="sync_movie"> <xs:sequence> <xs:element name="title" type="String"/> <xs:element name="director" type="String"/> </xs:sequence> </xs:complexType> <xs:simpleType name="String"> <xs:restriction base="xs:string"> </xs:restriction> </xs:simpleType> <xs:element name="message"> <xs:complexType> <xs:choice> <xs:element name="book" type="sync_book"/> <xs:element name="movie" type="sync_movie"/> </xs:choice> <xs:attribute name = "book" type="String"/> </xs:complexType> </xs:element> </xs:schema> Apparently this is a valid XSD (although probably bad naming convention). Mendix accepts this as XML_Schema and using that for an import mapping results in the following (correct) model:   The mapping of any valid XML message will now result in the error:  com.mendix.core.CoreException: com.mendix.modules.microflowengine.MicroflowException: com.mendix.integration.importer.mapping.ValueElement cannot be cast to com.mendix.integration.importer.mapping.ObjectElement <message book="Harry Potter"> <movie> <title>Harry Potter></title> <director>dunno</director> </movie> </message>   The only thing that 'works' is removing the 'book' element from the import mapping. I will be able to map all my objects except for books. Is there a way around this? I suppose I could make a custom Java mapping but only if there isn't another option since the actual XSD is several times larger than this example. Changing the XSD is not an option unfortunately.   Kind regards, Luc
asked
1 answers
4

Well thank you all for being my rubber duck.

Instead of removing the book element from the mapping, I removed the book attribute which was redundant anyway.

I suppose this problem still exists in Mendix, but it isn't my problem anymore. :) I don't suppose it happens a lot anyway.

answered