private org.xml.sax.Attributes convertAttributes(final Attributes jsoup) { final AttributesImpl sax = new AttributesImpl(); jsoup.forEach(a -> sax.addAttribute(NS, a.getKey(), a.getKey(), "", a.getValue())); return sax; }
private void setOuterHtml(Document doc) { int nrChildren = doc.body().children().size(); if (nrChildren != 1) { String message = "HTML must contain exactly one top level element (ignoring text nodes). Found " + nrChildren; if (nrChildren > 1) { String tagNames = doc.body().children().stream() .map(org.jsoup.nodes.Element::tagName) .collect(Collectors.joining(", ")); message += " elements with the tag names " + tagNames; } throw new IllegalArgumentException(message); } org.jsoup.nodes.Element root = doc.body().child(0); Attributes attrs = root.attributes(); Component.setElement(this, new Element(root.tagName())); attrs.forEach(a -> { String name = a.getKey(); String value = a.getValue(); getElement().setAttribute(name, value); }); doc.outputSettings().prettyPrint(false); setInnerHtml(root.html()); }