code: public static Document toDocument(JAXBElement<?> jaxbElement,
  			boolean prettyPrint) {
  
  		Document document = null;
  
  		try {
  			DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
  					.newInstance();
  			documentBuilderFactory.setNamespaceAware(true);
  			documentBuilderFactory.setIgnoringElementContentWhitespace(true);
  			documentBuilderFactory.isIgnoringComments();
  			documentBuilderFactory.setCoalescing(true);
  
  			document = documentBuilderFactory.newDocumentBuilder()
  					.newDocument();
  
  			String packName = jaxbElement.getDeclaredType().getPackage().getName();
  			JAXBContext jaxbContext;
  			if (packName.startsWith("org.mitre")){
  				jaxbContext = stixJaxbContext();
  			} else {
  				jaxbContext = JAXBContext.newInstance(packName);
  			}
  
  			Marshaller marshaller = jaxbContext.createMarshaller();
  
  			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
  					prettyPrint);
  
  			marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
  
  			try {
  				marshaller.marshal(jaxbElement, document);
  			} catch (JAXBException e) {
  				// otherwise handle non-XMLRootElements
  				QName qualifiedName = new QName(
  						STIXSchema.getNamespaceURI(jaxbElement), jaxbElement
  								.getClass().getSimpleName());
  
  				@SuppressWarnings({ "rawtypes", "unchecked" })
  				JAXBElement root = new JAXBElement(qualifiedName,
  						jaxbElement.getClass(), jaxbElement);
  
  				marshaller.marshal(root, document);
  			}
  
  			removeUnusedNamespaces(document);
  
  		} catch (ParserConfigurationException e) {
  			throw new RuntimeException(e);
  		} catch (JAXBException e) {
  			throw new RuntimeException(e);
  		}
  
  		return document;
  	}
docs: Returns a Document for a JAXBElement
  
  @param jaxbElement
  JAXB representation of an XML Element
  @param prettyPrint
  True for pretty print, otherwise false
  @return The Document representation