@Override public boolean match(final Node node, final String expression) { String text = node.getTextContent(); return text.contains(expression); } }
/** * Gets the combined text contents of each element in the set of * matched elements, including their descendants. * Text is HTML decoded for text nodes. */ public String text() { if (nodes.length == 0) { return StringPool.EMPTY; } StringBuilder sb = new StringBuilder(); for (Node node : nodes) { sb.append(node.getTextContent()); } return sb.toString(); }
assertEquals("Fred Bloggs", man.getChild(0).getTextContent());
@Test void testPeopleXml() throws IOException { File file = new File(testDataRoot, "people.xml"); String xmlContent = FileUtil.readString(file); LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder(); lagartoDOMBuilder.enableXmlMode(); Document doc = lagartoDOMBuilder.parse(xmlContent); assertEquals(2, doc.getChildNodesCount()); // not 3! XmlDeclaration xml = (XmlDeclaration) doc.getFirstChild(); assertEquals(0, xml.getAttributesCount()); Element peopleList = (Element) doc.getChild(1); assertEquals(1, peopleList.getChildNodesCount()); Element person = peopleList.getFirstChildElement(); assertEquals(3, person.getChildNodesCount()); Element name = (Element) person.getChild(0); assertEquals("Fred Bloggs", name.getTextContent()); assertEquals("Male", person.getChild(2).getTextContent()); xmlContent = StringUtil.removeChars(xmlContent, "\n\r\t"); assertEquals(xmlContent, doc.getHtml()); assertTrue(doc.check()); }
@Override public boolean match(final Node node, final String expression) { String text = node.getTextContent(); return text.contains(expression); } }
@Override public boolean match(Node node, String expression) { String text = node.getTextContent(); return text.contains(expression); } }
@Override public boolean match(Node node, String expression) { String text = node.getTextContent(); return text.contains(expression); } }
/** * Gets the combined text contents of each element in the set of * matched elements, including their descendants. * Text is HTML decoded for text nodes. */ public String text() { StringBuilder sb = new StringBuilder(); for (Node node : nodes) { sb.append(node.getTextContent()); } return sb.toString(); }
/** * Gets the combined text contents of each element in the set of * matched elements, including their descendants. * Text is HTML decoded for text nodes. */ public String text() { StringBuilder sb = new StringBuilder(); for (Node node : nodes) { sb.append(node.getTextContent()); } return sb.toString(); }
/** * Gets the combined text contents of each element in the set of * matched elements, including their descendants. * Text is HTML decoded for text nodes. */ public String text() { if (nodes.length == 0) { return StringPool.EMPTY; } StringBuilder sb = new StringBuilder(); for (Node node : nodes) { sb.append(node.getTextContent()); } return sb.toString(); }
/** * Returns the text content of this node and its descendants. */ public String getTextContent() { StringBuilder sb = new StringBuilder(getChildNodesCount() + 1); if (nodeValue != null) { if ((nodeType == NodeType.TEXT) || (nodeType == NodeType.CDATA)) { sb.append(nodeValue); } } if (childNodes != null) { for (int i = 0, childNodesSize = childNodes.size(); i < childNodesSize; i++) { Node childNode = childNodes.get(i); sb.append(childNode.getTextContent()); } } return sb.toString(); }
private String extractValue(String attribute, Node element) { if (!JOrphanUtils.isBlank(attribute)) { return element.getAttribute(attribute); } else { return element.getTextContent().trim(); } } }
@Override public List<String> extractList(String data) { List<String> strings = new LinkedList<>(); Jerry doc = jerry(data); Node[] nodes = doc.$(query).get(); for (Node node : nodes) { switch (outType) { case TYPE_TEXT: strings.add(parse(node.getTextContent())); break; case TYPE_HTML: strings.add(parse(node.getHtml())); break; default: strings.add(parse(node.getAttribute(outType))); break; } } return strings; }