[jboss-user] [Beginners Corner] - Jboss unmarshalling

vitor_b do-not-reply at jboss.com
Thu Sep 6 12:45:05 EDT 2007


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);
  | 	}

Could you tell me if it is possible to unmarshall such xml file? If the answer is yes, then please tell me how to do it.

vitor_b

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4081755#4081755

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4081755



More information about the jboss-user mailing list