@Test public void testInsertNode_NodeDoesNotExist() throws Exception { InsertNode rn = new InsertNode("/Root/AnotherNode"); rn.setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder.newInstance()); Document merged = rn.merge(XmlHelper.createDocument(ORIGINAL), XmlHelper.createDocument(REPLACEMENT)); XmlUtils xml = new XmlUtils(); xml.setSource(merged); assertNotNull(xml.getSingleTextItem(XPATH_ORIGINAL_NODE)); assertEquals(DATA_A, xml.getSingleTextItem(XPATH_ORIGINAL_NODE)); assertEquals(DATA_B, xml.getSingleTextItem("/Root/AnotherNode/NewNode")); }
@Override public Document merge(Document original, Document newDoc) throws Exception { if (StringUtils.isEmpty(getXpathToParentNode())) { throw new Exception("No parent node configured"); } Document resultDoc = original; XmlUtils xml = create(resultDoc); Node parent = resolve(xml, getXpathToParentNode()); if (parent.getOwnerDocument() == null) { throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]"); } xml.appendNode(newDoc.getDocumentElement(), parent); return resultDoc; }
InsertNode extends XpathMergeImpl { @Override public Document merge(Document original, Document newDoc) throws Exception { if (StringUtils.isEmpty(getXpathToParentNode())) { throw new Exception("No parent node configured"); } Document resultDoc = original; XmlUtils xml = create(resultDoc); Node parent = resolve(xml, getXpathToParentNode()); if (parent.getOwnerDocument() == null) { throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]"); } xml.appendNode(newDoc.getDocumentElement(), parent); return resultDoc; } }
InsertNode extends XpathMergeImpl { @Override public Document merge(Document original, Document newDoc) throws Exception { if (StringUtils.isEmpty(getXpathToParentNode())) { throw new Exception("No parent node configured"); } Document resultDoc = original; XmlUtils xml = create(resultDoc); Node parent = resolve(xml, getXpathToParentNode()); if (parent.getOwnerDocument() == null) { throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]"); } xml.appendNode(newDoc.getDocumentElement(), parent); return resultDoc; } InsertNode();  InsertNode(String xpath); }
InsertNode extends XpathMergeImpl { @Override public Document merge(Document original, Document newDoc) throws Exception { if (StringUtils.isEmpty(getXpathToParentNode())) { throw new Exception("No parent node configured"); } Document resultDoc = original; XmlUtils xml = create(resultDoc); Node parent = resolve(xml, getXpathToParentNode()); if (parent.getOwnerDocument() == null) { throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]"); } xml.appendNode(newDoc.getDocumentElement(), parent); return resultDoc; } InsertNode();  InsertNode(String xpath); @Override Document merge(Document original, Document newDoc); String getXpathToParentNode(); void setXpathToParentNode(String xpath); }
InsertNode extends XpathMergeImpl { @Override public Document merge(Document original, Document newDoc) throws Exception { if (StringUtils.isEmpty(getXpathToParentNode())) { throw new Exception("No parent node configured"); } Document resultDoc = original; XmlUtils xml = create(resultDoc); Node parent = resolve(xml, getXpathToParentNode()); if (parent.getOwnerDocument() == null) { throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]"); } xml.appendNode(newDoc.getDocumentElement(), parent); return resultDoc; } InsertNode();  InsertNode(String xpath); @Override Document merge(Document original, Document newDoc); String getXpathToParentNode(); void setXpathToParentNode(String xpath);  }