@Override public String toString() { return html(); }
/** Get the HTML representation of these attributes. @return HTML @throws SerializationException if the HTML representation of the attributes cannot be constructed. */ public String html() { StringBuilder accum = new StringBuilder(); try { html(accum, (new Document("")).outputSettings()); // output settings a bit funky, but this html() seldom used } catch (IOException e) { // ought never happen throw new SerializationException(e); } return accum.toString(); }
void outerHtmlHead(final Appendable accum, int depth, final Document.OutputSettings out) throws IOException { if (out.prettyPrint() && (tag.formatAsBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline())) { if (accum instanceof StringBuilder) { if (((StringBuilder) accum).length() > 0) indent(accum, depth, out); } else { indent(accum, depth, out); } } accum.append('<').append(tagName()); if (attributes != null) attributes.html(accum, out); // selfclosing includes unknown tags, isEmpty defines tags that are always empty if (childNodes.isEmpty() && tag.isSelfClosing()) { if (out.syntax() == Document.OutputSettings.Syntax.html && tag.isEmpty()) accum.append('>'); else accum.append(" />"); // <img> in html, <img /> in xml } else accum.append('>'); }
public void tail(Node node, int depth) { if (node.getClass().equals(Element.class)) { Element elm = (Element) node; XMLElement anno = builder.add(beginMap.get(node), XMLElement.class); anno.setTag(elm.tagName()); anno.setId(elm.id()); anno.setSelector(elm.cssSelector()); anno.setAttributes(elm.attributes().html()); if (elm.className().isEmpty()) anno.setCls(elm.attr("type")); else anno.setCls(elm.className()); annotationMap.put(elm.cssSelector(), anno); if (!this.preserveWhitespace) if (elm.isBlock() || ArrayUtils.contains(blockElements, elm.tagName())) builder.add("\n"); } }
@Override public void tail(Node node, int depth) { if (node instanceof Element) { Element elm = (Element) node; XMLElement anno = builder.add(beginMap.get(node), XMLElement.class); anno.setTag(elm.tagName()); anno.setId(elm.id()); anno.setSelector(elm.cssSelector()); anno.setAttributes(elm.attributes().html()); if (elm.className().isEmpty()) anno.setCls(elm.attr("type")); else anno.setCls(elm.className()); annotationMap.put(elm.cssSelector(), anno); if (!this.preserveWhitespace) if (elm.isBlock() || ArrayUtils.contains(blockElements, elm.tagName())) builder.add("\n"); } else if (node instanceof XmlDeclaration) { XmlDeclaration xmlDecl = (XmlDeclaration) node; XmlDeclarationAnnotation anno = builder.add(beginMap.get(node), XmlDeclarationAnnotation.class); anno.setOuterHtml(xmlDecl.outerHtml()); } }