Skip to main content

Schema component with attribute but no elements

3 replies [Last post]
amarkel
Offline
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"?>

file:/net/rockpile/export1/workspaces/users/arieh/x2-05/scrk/usr/proto/com/sun/scn/asset/maps/impl/daqimmap.xsd
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(AbstractUnmarshallerImpl.java:315)

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) ?

Arieh

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sekhar
Offline
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 https://jaxb.dev.java.net/servlets/ProjectIssues .

rationalpi
Offline
Joined: 2005-10-14
Points: 0

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

https://jaxb.dev.java.net/issues/show_bug.cgi?id=135

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

Joshua Smith

rationalpi
Offline
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