XformResource extends BaseResource<Form> { static String convertToOdkCollect(String xml, String title) throws IOException, SAXException { Document oldDoc = XmlUtils.parse(xml); Document doc = XmlUtils.createDocumentBuilder().newDocument(); Element root = (Element) doc.importNode(oldDoc.getDocumentElement(), true); root = (Element) doc.renameNode(root, HTML_NAMESPACE, "h:form"); doc.appendChild(root); Element head = doc.createElementNS(HTML_NAMESPACE, "h:head"); Element titleElement = XmlUtils.appendChild(head, HTML_NAMESPACE, "h:title"); titleElement.setTextContent(title); Element body = doc.createElementNS(HTML_NAMESPACE, "h:body"); Element model = requireDescendant(root, XFORMS_NAMESPACE, "model"); List<Node> nodesAfterModel = new ArrayList<>(); Node nextSibling = model.getNextSibling(); while (nextSibling != null) { nodesAfterModel.add(nextSibling); nextSibling = nextSibling.getNextSibling(); } head.appendChild(model); for (Node node : nodesAfterModel) { body.appendChild(node); } root.appendChild(head); root.appendChild(body); return XformsUtil.doc2String(doc); } XformResource(); static Collection<Form> getXformForms(FormService formService);  }
@Test public void convertToOdkCollect() throws Exception { String input = getStringResource(getClass(), "sample-original-form1.xml"); String expected = getStringResource(getClass(), "expected-result-form1.xml"); String actual = XformResource.convertToOdkCollect(input, "Form title"); assertXmlEqual(expected, actual); }