Hi,
I am ttrying to marshall/unmarshall elements that have a substitutionGroup
defined
It seems that when a top level element is defined with the substitutionGroup
then JAXB doesnt define the @XmlRootElement and marshalling fails.
If the substitutionGroup from the element-ext is removed then the annotation
is inserted and all is fine, but I cant see a way to get XJC to treat this
element as a top level element, and allow substitution
I am using jaxb2.1.9
the schema used is
<xs:schema xmlns:local="someuri" xmlns:xs="
http://www.w3.org/2001/XMLSchema"
targetNamespace="someuri" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:complexType name="base" abstract="true">
<xs:attribute name="attr1" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="element-base" type="local:base" abstract="true"/>
<xs:element name="element-ext" substitutionGroup="local:element-base">
<xs:complexType>
<xs:complexContent>
<xs:extension base="local:base">
<xs:attribute name="attr3" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
this generates
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB)
Reference Implementation, vhudson-jaxb-ri-2.1-646
// See
http://java.sun.com/xml/jaxb http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the
source schema.
// Generated on: 2008.11.14 at 10:38:51 PM GMT
//
package someuri;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained
within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <extension base="{someuri}base">
* <attribute name="attr3" use="required"
type="{
http://www.w3.org/2001/XMLSchema}string" />
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
public class ElementExt
extends Base
{
@XmlAttribute(required = true)
protected String attr3;
/**
* Gets the value of the attr3 property.
*
* @return
* possible object is
* {_at_link String }
*
*/
public String getAttr3() {
return attr3;
}
/**
* Sets the value of the attr3 property.
*
* @param value
* allowed object is
* {_at_link String }
*
*/
public void setAttr3(String value) {
this.attr3 = value;
}
}
it then it is unmarshalled like this
JAXBContext context = JAXBContext.newInstance(ElementExt.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.unmarshal(new StringReader(
"<local:element-ext attr1='S' attr3='s' xsi:schemaLocation='someuri
test2.xsd' xmlns:xsi='
http://www.w3.org/2001/XMLSchema-instance'
xmlns:local='someuri'/>"));
then I get the following exception
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected
element (uri:"someuri", local:"element-ext"). Expected elements are (none)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:609)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:239)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1015)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:452)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:433)
at
com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:220)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:322)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:779)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
at
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:194)
at subst.Sub.main(Sub.java:24)
--
View this message in context: http://www.nabble.com/problem-marshlled-elements-when-substitutionGroup-defined-tp20510298p20510298.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.