/** * Tests that createChildElement does as it says. */ public void testCreateChildElement() { init("<p>first child</p>"); Element root = doc.getDocumentElement(); doc.createChildElement(root, "child", Collections.<String, String> emptyMap()); assertOperationResult("<p>first child</p><child/>"); }
/** * Tests that createChildElement does as it says. */ public void testCreateChildElement() { init("<p>first child</p>"); Element root = doc.getDocumentElement(); doc.createChildElement(root, "child", Collections.<String, String> emptyMap()); assertOperationResult("<p>first child</p><child/>"); }
@Override public void setElementAttributes(E element, Attributes attrs) { Preconditions.checkArgument(element != getDocumentElement(), "Cannot touch root element"); try { begin(); consume(setAttributes(attrs, at(Locator.before(doc, element)))); } finally { end(); } }
@Override public void updateElementAttributes(E element, Map<String, String> attrs) { Preconditions.checkArgument(element != getDocumentElement(), "Cannot touch root element"); try { begin(); consume(updateAttributes(attrs, at(Locator.before(doc, element)))); } finally { end(); } }
/** * Test basic get attribute. */ public void testGetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); assertEquals("0", doc.getAttribute(e, "t")); assertEquals("hi", doc.getAttribute(e, "s")); }
/** * Test basic get attribute. */ public void testGetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); assertEquals("0", doc.getAttribute(e, "t")); assertEquals("hi", doc.getAttribute(e, "s")); }
/** * Test set attribute overrides and removes old attributes, as opposed to * update. */ public void testSetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); doc.setElementAttributes(e, new AttributesImpl("just", "this")); assertEquals(null, doc.getAttribute(e, "t")); assertEquals(null, doc.getAttribute(e, "s")); assertEquals("this", doc.getAttribute(e, "just")); }
/** * Test set attribute overrides and removes old attributes, as opposed to * update. */ public void testSetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); doc.setElementAttributes(e, new AttributesImpl("just", "this")); assertEquals(null, doc.getAttribute(e, "t")); assertEquals(null, doc.getAttribute(e, "s")); assertEquals("this", doc.getAttribute(e, "just")); }
public void testMoveNodes() throws Exception { Element root = doc.getDocumentElement().getFirstChild().asElement(); Node from = root.getLastChild(); doc.moveSiblings(Point.start(doc, root), from, null); root = doc.getDocumentElement().getFirstChild().asElement(); Node stuff = root.getFirstChild().getNextSibling(); from = stuff.getNextSibling(); root = doc.getDocumentElement().getFirstChild().asElement(); doc.moveSiblings(Point.end((Node) root), root.getFirstChild(), root.getLastChild()); assertOperationResult("<?a \"s\"=\"S\"?><root><?a \"e\"=\"E\" \"s\"?><after/>"
public void testMoveNodes() throws Exception { Element root = doc.getDocumentElement().getFirstChild().asElement(); Node from = root.getLastChild(); doc.moveSiblings(Point.start(doc, root), from, null); root = doc.getDocumentElement().getFirstChild().asElement(); Node stuff = root.getFirstChild().getNextSibling(); from = stuff.getNextSibling(); root = doc.getDocumentElement().getFirstChild().asElement(); doc.moveSiblings(Point.end((Node) root), root.getFirstChild(), root.getLastChild()); assertOperationResult("<?a \"s\"=\"S\"?><root><?a \"e\"=\"E\" \"s\"?><after/>"