public void removeAttributes(Predicate<Attribute> predicate, boolean recurse) { removeAttributes(predicate); if (recurse) { for (final Element child : getElements()) { child.removeAttributes(predicate, true); } } }
/** * Changes element names recursively. * * @param modifier A function that take name and returns new name. * @param recurse If {@code true}, then this is applied recursively. */ public void changeName(Function<String, String> modifier, boolean recurse) { changeName(modifier); if (recurse) { for (final Element child : getElements()) { child.changeName(modifier, true); } } }
/** * Changes the value of attributes that have a given name. * * @param name The attribute name. * @param modifier A function that take value and returns new value. * @param recurse If {@code true}, then this is applied recursively. */ public void changeAttributeValue(String name, Function<String, String> modifier, boolean recurse) { changeAttributeValue(name, modifier); if (recurse) { for (final Element child : getElements()) { child.changeAttributeValue(name, modifier, true); } } }
private void analyze(File file, Element element) { for (final SPath path : margs.paths) { if (path.matchesElement(element)) { final String s = element.getText(null); checkClassName(s, file, element.getQName()); } for (final Attribute att : element.getAttributes()) { if (path.matchesAttribute(element, att.getName())) { final String s = att.getValue(); checkClassName(s, file, element.getQName() + "/@" + att.getName()); } } } for (final Element child : element.getElements()) { analyze(file, child); } }
@Test public void testGetChildren() { final Element root = new Element(NAME); assertEquals(null, root.getLastChild()); final Element child1 = root.addElement(NAME1); final Element child2 = root.addElement(NAME2); final Element child3 = root.addElement(NAME1); child3.addAttribute(NAME, VALUE); final Comment child4 = root.addComment("Hello"); assertEquals(4, root.getChildrenCount()); assertTrue(root.hasChildren(Element.class)); assertTrue(root.hasChildren(Comment.class)); assertFalse(root.hasChildren(Text.class)); assertEquals(child4, root.getLastChild()); assertEquals(child1, root.getChild(Element.class)); assertEquals(child1, root.getElementNamed(NAME1)); assertEquals(3, root.getChildrenCount(Element.class)); assertEquals(2, root.getChildrenCount(Element.class, Element.named(NAME1))); assertEquals(child2, root.getChild(Element.class, Element.named(NAME2))); assertEquals(child2, root.getChildAt(Element.class, Element.named(NAME2), 0)); assertEquals(null, root.getChildAt(Element.class, Element.named(NAME2), 1)); assertEquals(child3, root.getChildAt(2)); assertEquals(child3, root.getChildAt(Element.class, 2)); assertEquals(child4, root.getChildAt(Comment.class, 0)); assertEquals(3, Iterables.size(root.getElements())); assertEquals(1, Iterables.size(root.getComments())); assertEquals(0, Iterables.size(root.getTexts())); assertEquals(child3, root.getElementNamedWithAttribute(NAME1, NAME, VALUE)); }