- if (schema instanceof ContainerSchemaNode || schema instanceof ListSchemaNode) {
- doc.appendChild(createXmlRootElement(doc, data, (SchemaNode) schema, codecProvider));
- return doc;
- } else {
- throw new UnsupportedDataTypeException(
- "Schema can be ContainerSchemaNode or ListSchemaNode. Other types are not supported yet.");
+ /**
+ * Converts Data DOM structure to XML Document for specified XML Codec Provider. The CompositeNode
+ * data parameter enters as root of Data DOM tree and will be transformed to root in XML Document. The child
+ * nodes of Data Tree are transformed accordingly.
+ *
+ * @param data Data DOM root element
+ * @param codecProvider XML Codec Provider
+ * @return new instance of XML Document
+ * @throws UnsupportedDataTypeException
+ */
+ public static Document toDocument(CompositeNode data, XmlCodecProvider codecProvider)
+ throws UnsupportedDataTypeException {
+ Preconditions.checkNotNull(data);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ Document doc = null;
+ try {
+ DocumentBuilder bob = dbf.newDocumentBuilder();
+ doc = bob.newDocument();
+ } catch (ParserConfigurationException e) {
+ return null;