Hello
I created a class which uses jboss Unmarshaller. It works just fine, but i cannot unmarshall xml file which does not contain the main element from schema. That means when file i want to unmarshall contains some element from schema, but this is not a global element i receive exception:
Exception in thread "main" org.jboss.xb.binding.JBossXBException: Failed to parse source: Element account is not bound as a global element.
at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse (SaxJBossXBParser.java:156)
...
This the class i created:
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import org.jboss.xb.binding.JBossXBException; import org.jboss.xb.binding.Unmarshaller; import org.jboss.xb.binding.UnmarshallerFactory; import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding; import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder; public class XBUnmarshaller { SchemaBinding schema; Unmarshaller unmarshaller; private void setUp(){ unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); } public XBUnmarshaller(String schemaFile) throws FileNotFoundException { this(new FileInputStream(new File(schemaFile))); } public XBUnmarshaller(InputStream stream){ setUp(); schema = XsdBinder.bind(stream, "UTF-8"); } public Object unmarshallXml(String fileName) throws FileNotFoundException, JBossXBException{ return unmarshallXml(new FileInputStream(new File(fileName))); } public Object unmarshallXml(InputStream inputXml) throws JBossXBException{ return unmarshaller.unmarshal(inputXml, schema); }