KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using the partial-unmarshalling example of JAXB , but I am unable to unmarshal XML-Elements which are not on the root-level (cause they don't have an @XmlRootElement tag). In my example I tried to read the shipTo-Element instead of the purchaseOrder-Element. Normally I would work with JAXBElement unmarshal(Source source,Class declaredType) but since the example is using an UnmarshallerHandler and a XMLFilterImpl I don't know where to tell Jaxb which Class it should use. My error message is: Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"shipTo"). Expected elements are <{}comment>,<{}purchaseOrder>,<{}purchaseOrders> I googled around a lot, but didn't find anything useful yet. Here is the example code from the JaxB-Webpage: Main.java public class Main { public static void main( String[] args ) throws Exception { // create JAXBContext for the primer.xsd JAXBContext context = JAXBContext.newInstance("primer"); // create a new XML parser SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); XMLReader reader = factory.newSAXParser().getXMLReader(); // prepare a Splitter Splitter splitter = new Splitter(context); // connect two components reader.setContentHandler(splitter); for( int i=0; i<args.length; i++ ) { // parse all the documents specified via the command line. // note that XMLReader expects an URL, not a file name. // so we need conversion. reader.parse(new File(args[i]).toURL().toExternalForm()); } } } Splitter.java public class Splitter extends XMLFilterImpl { public Splitter( JAXBContext context ) { this.context = context; } /** * We will create unmarshallers from this context. */ private final JAXBContext context; public void s
Tags (comma-separated)
Save Edits
Cancel