Skip to main content

Schema component with attribute but no elements

3 replies [Last post]
Joined: 2004-05-13
Points: 0

I am defining a Java class that has annotations for
XmlAttributes for its two fields.

While I can create an XML document programmatically,
JAXB fails to read it into the Java-bound classes:

Here is the instance document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Exception in thread "main" javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-complex-type.2.1: Element 'argument' must have no character or element information item [children], because the type's content type is empty.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(

Here is the 'argument' class:

@XmlType( name = "argument" )
public class ArgMapping {
private String imName;
private String daqName;

public ArgMapping() { super(); }

public ArgMapping(String theIMName, String theDAQName)
imName = theIMName;
daqName = theDAQName;

@XmlAttribute( name = "InfoModel", required = true )
public String getIMName() { return imName; }

public void setIMName( String theName ) {
imName = theName; }

@XmlAttribute( name = "DAQ" )
public String getDAQName() { return daqName; }

public void setDAQName( String theName ) {
daqName = theName; }

Can't components be defined that have only attributes
(no elements) ?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-25
Points: 0

> Can't components be defined that have only attributes
> (no elements) ?
Yes i.e. you can have a class with all properties/fields annotated with @XmlAttribute.

Please file an issue on .

Joined: 2005-10-14
Points: 0

This bug bit me as well. It looks like it was submitted and worked.

From the resolution:
***begin quote***
Fixed for 2.0.1. In 2.0, to work around this problem, pass in to the marshaller, not OutputStream.
***end quote***

Joshua Smith

Joined: 2005-10-14
Points: 0

I went ahead and tried the work around solution and it works perfectly.

kohsuke is the one that fixed the bug and posted the work around.

Thank kohsuke.

Joshua Smith