@Override public boolean match(final Node node) { return node.getNextSiblingName() == null; } }
@Override public boolean match(final Node node) { return (node.getSiblingNameIndex() == 0) && (node.getNextSiblingName() == null); } }
@Test void testTwoHtml() throws IOException { File file = new File(testDataRoot, "two.html"); String htmlContent = FileUtil.readString(file); Document document = new LagartoDOMBuilder().parse(htmlContent); Node html = new NodeSelector(document).select("html").get(0); assertNotNull(html); Node body = new NodeSelector(html).selectFirst("body"); Element h1 = body.getFirstChildElement(); assertEquals("h1", h1.getNodeName()); Node comment1 = body.getFirstChild().getNextSibling(); assertEquals(Node.NodeType.COMMENT, comment1.getNodeType()); Element p = (Element) new NodeSelector(body).selectFirst("p"); assertEquals(h1, p.getPreviousSiblingElement()); assertEquals(h1, comment1.getNextSiblingElement()); assertNull(comment1.getNextSiblingName()); // check if filter works just for sub elements List<Node> p_ems = new NodeSelector(p).select("em"); assertEquals(1, p_ems.size()); Element script = (Element) new NodeSelector(html).selectFirst("script"); assertEquals("text/javascript", script.getAttribute("type")); assertTrue(document.check()); }
@Override public boolean match(Node node) { return node.getNextSiblingName() == null; } }
@Override public boolean match(Node node) { return node.getNextSiblingName() == null; } }
@Override public boolean match(final Node node) { return node.getNextSiblingName() == null; } }
@Test void testNamesAndChilds() { Document document = new LagartoDOMBuilder().parse("<div id='top'><p id='id1'>one</p><span id='t1'>text1</span><p id='id2'>two</p><span id='t2'>text2</span><p id='id3'>three</p><span id='t3'>text3</span></div>"); Element topDiv = (Element) document.getFirstChild(); Element p1 = (Element) topDiv.getFirstChild(); assertEquals("id1", p1.getAttribute("id")); Element s1 = (Element) p1.getNextSibling(); assertEquals("t1", s1.getAttribute("id")); Element p2 = (Element) s1.getNextSiblingElement(); assertEquals("id2", p2.getAttribute("id")); Element p3 = (Element) p2.getNextSiblingElement().getNextSiblingElement(); assertEquals("id3", p3.getAttribute("id")); Element s3 = (Element) p3.getNextSibling(); assertEquals("t3", s3.getAttribute("id")); assertEquals(p2, p1.getNextSiblingName()); assertEquals(s3, s1.getNextSiblingName().getNextSiblingName()); assertEquals(p2, p3.getPreviousSiblingName()); assertEquals(s1, s3.getPreviousSiblingName().getPreviousSiblingName()); assertEquals(p1, topDiv.getFirstChild()); assertEquals(p1, topDiv.getFirstChildElement()); assertEquals(p1, topDiv.getFirstChildElement("p")); assertEquals(s1, topDiv.getFirstChildElement("span")); assertEquals(s3, topDiv.getLastChild()); assertEquals(s3, topDiv.getLastChildElement()); assertEquals(p3, topDiv.getLastChildElement("p")); assertEquals(s3, topDiv.getLastChildElement("span")); assertTrue(document.check()); }
@Override public boolean match(Node node) { return (node.getSiblingNameIndex() == 0) && (node.getNextSiblingName() == null); } }
@Override public boolean match(Node node) { return (node.getSiblingNameIndex() == 0) && (node.getNextSiblingName() == null); } }
@Override public boolean match(final Node node) { return (node.getSiblingNameIndex() == 0) && (node.getNextSiblingName() == null); } }