KyeroDocument extends XmlConvertableDocument<Root, KyeroVersion> { @Override public void setDocumentVersion(KyeroVersion version) { try { Document doc = this.getDocument(); Element node = (Element) XmlUtils .newXPath("/io:root/io:kyero/io:feed_version", doc) .selectSingleNode(doc); if (node == null) { Element parentNode = (Element) XmlUtils .newXPath("/io:root/io:kyero", doc) .selectSingleNode(doc); if (parentNode == null) { Element grandParentNode = (Element) XmlUtils .newXPath("/io:root", doc) .selectSingleNode(doc); if (grandParentNode == null) { LOGGER.warn("Can't find a <root> element in the document!"); return; } parentNode = doc.createElement("kyero"); grandParentNode.insertBefore(parentNode, grandParentNode.getFirstChild()); } node = doc.createElement("feed_version"); parentNode.insertBefore(node, parentNode.getFirstChild()); } String newVersion = version.toXmlVersion(); node.setTextContent(newVersion); } catch (JaxenException ex) { LOGGER.error("Can't evaluate XPath expression!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); } } KyeroDocument(Document document); @Override KyeroVersion getDocumentVersion(); @Override KyeroVersion getLatestVersion(); static boolean isReadable(Document doc); static KyeroDocument newDocument(); static KyeroDocument newDocument(Root root); @Override void setDocumentVersion(KyeroVersion version); @Override Root toObject();  }
@Test public void testSetDocumentVersion() { KyeroDocument doc; try { doc = new KyeroDocument(buildExampleDocument("")); Assert.assertNull("no version", doc.getDocumentVersion()); doc.setDocumentVersion(KyeroVersion.V3); Assert.assertEquals( "version 3", KyeroVersion.V3, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of KyeroDocument.setDocumentVersion failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of KyeroDocument.setDocumentVersion failed!"); } }