Skip to content

Instantly share code, notes, and snippets.

@kartikshah
Created February 1, 2012 20:56
Show Gist options
  • Save kartikshah/1719270 to your computer and use it in GitHub Desktop.
Save kartikshah/1719270 to your computer and use it in GitHub Desktop.
Pass child element'd Node to unmarshal
public class JaxbUnmarshallerWithDocBuilder {
public static void main(String args[]){
try{
JAXBContext jc = JAXBContext.newInstance("com.kartikshah.api.account.wsdl");
Unmarshaller u = jc.createUnmarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(JaxbUnmarshallerWithDocBuilder.class.getResource("account.xml"));
Node fooSubtree = doc.getFirstChild();
JAXBElement<Account> account = u.unmarshal( fooSubtree, Account.class);
}
catch (Exception e){
// ... Omitted for brevity
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment