Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 354130

Summary: Incorrect namespace generated for @XmlPath and @XmlAttribute are present for an attribute
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Denise Smith <denise.mahar>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: denise.mahar, eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://stackoverflow.com/questions/6976034/error-in-xml-schema-generated-from-moxy-jaxb-when-using-xmlpath-and-namespace
Whiteboard:
Attachments:
Description Flags
Code demonstrating the bug
none
Proposed changes and tests none

Description Blaise Doughan CLA 2011-08-08 09:23:26 EDT
Given the following class:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
public class FooBar {
    @XmlAttribute
    @XmlPath("test/@foo")
    private boolean foo;
}

The following incorrect schema is generated:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified">
   <xsd:complexType name="fooBar">
      <xsd:sequence>
         <xsd:element name="test" minOccurs="0">
            <xsd:complexType>
               <xsd:sequence/>
               <xsd:attribute ref="ns0:foo"/>
            </xsd:complexType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="fooBar" type="ns0:fooBar"/>
   <xsd:attribute name="foo" type="xsd:boolean" use="required"/>
</xsd:schema>

WORKAROUND:

If we remove the @XmlAttribute Annotation:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
public class FooBar {
    //@XmlAttribute
    @XmlPath("test/@foo")
    private boolean foo;
}

Then the correct XML schema is generated:

class org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified">
   <xsd:complexType name="fooBar">
      <xsd:sequence>
         <xsd:element name="test" minOccurs="0">
            <xsd:complexType>
               <xsd:sequence>
                  <xsd:element name="@foo" type="xsd:boolean"/>
               </xsd:sequence>
            </xsd:complexType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="fooBar" type="ns0:fooBar"/>
</xsd:schema>
Comment 1 Blaise Doughan CLA 2011-08-08 09:24:24 EDT
Created attachment 201078 [details]
Code demonstrating the bug
Comment 2 Blaise Doughan CLA 2011-08-08 10:40:21 EDT
CORRECTION

The workaround is not valid as it produces:

     <xsd:element name="@foo" type="xsd:boolean"/>
Comment 3 Denise Smith CLA 2011-08-08 14:45:46 EDT
Created attachment 201098 [details]
Proposed changes and tests
Comment 4 Denise Smith CLA 2011-08-08 15:56:00 EDT
Fixed in 2.3 and 2.4.
Modified AnnotationsProcessor - the processing of XmlPath annotation was not allowing for the XmlPath to be to an attribute.

Also changed behavior so that if an @XmlAttribute was specified by the XmlPath was to an element the XmlPath annotation "wins".
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:05:58 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink