Document doc = ...//create HTML document Elements htmlElements = doc.children(); htmlElements.traverse(new MyHtmlElementVisitor());
Set<Document> alreadyExported = new HashSet<Document>(); for(Document parentDocument:Documents){ ExportToPdf(parentDocument); for(Document childDocument:parentDocument.children()){ if(!aldreadyExported.contains(childDocument)){ ExportToPdf(childDocument); alreadyExported.add(childDocument); } } }
public static JXDocument create(Document doc){ Elements els = doc.children(); return new JXDocument(els); }
public static JXDocument create(String html){ Elements els = Jsoup.parse(html).children(); return new JXDocument(els); }
public static JXDocument create(String html){ Elements els = Jsoup.parse(html).children(); return new JXDocument(els); }
public static JXDocument create(Document doc){ Elements els = doc.children(); return new JXDocument(els); }
private static StringBuilder createHeaderInjectionCall(String content) { StringBuilder inlineContent = new StringBuilder(); Document document = Jsoup.parse(content, "", Parser.xmlParser()); for (Element element : document.children()) { String tagName = element.tagName(); inlineContent.append("_inlineHeader('"); inlineContent.append(tagName).append("',"); inlineContent.append(makeJsString(element.html())); inlineContent.append(");\n"); } return inlineContent; }
/** * Returns a document whose {@code <body>} element contains the given HTML fragment. */ private Document getFragmentAsDocument(CharSequence value) { // using the XML parser ensures that all elements in the input are retained, also if they actually are not allowed at the given // location; E.g. a <td> element isn't allowed directly within the <body> element, so it would be used by the default HTML parser. // we need to retain it though to apply the given white list properly; See HV-873 Document fragment = Jsoup.parse( value.toString(), "", Parser.xmlParser() ); Document document = Document.createShell( "" ); // add the fragment's nodes to the body of resulting document Iterator<Element> nodes = fragment.children().iterator(); while ( nodes.hasNext() ) { document.body().appendChild( nodes.next() ); } return document; }
String decl = "<" + new String(bytes, 2, length - 4) + ">"; org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(decl, documentIRI, Parser.xmlParser()); for (org.jsoup.nodes.Element el : doc.children()) { if ("xml".equalsIgnoreCase(el.tagName())) { String enc = el.attr("encoding");
path.clear(); all.clear(); parse(doc.children());
/** * Returns a document whose {@code <body>} element contains the given HTML fragment. */ private Document getFragmentAsDocument(CharSequence value) { // using the XML parser ensures that all elements in the input are retained, also if they actually are not allowed at the given // location; E.g. a <td> element isn't allowed directly within the <body> element, so it would be used by the default HTML parser. // we need to retain it though to apply the given white list properly; See HV-873 Document fragment = Jsoup.parse( value.toString(), "", Parser.xmlParser() ); Document document = Document.createShell( "" ); // add the fragment's nodes to the body of resulting document Iterator<Element> nodes = fragment.children().iterator(); while ( nodes.hasNext() ) { document.body().appendChild( nodes.next() ); } return document; } }
/** * Returns a document whose {@code <body>} element contains the given HTML fragment. */ private Document getFragmentAsDocument(CharSequence value) { // using the XML parser ensures that all elements in the input are retained, also if they actually are not allowed at the given // location; E.g. a <td> element isn't allowed directly within the <body> element, so it would be used by the default HTML parser. // we need to retain it though to apply the given white list properly; See HV-873 Document fragment = Jsoup.parse( value.toString(), baseURI, Parser.xmlParser() ); Document document = Document.createShell( baseURI ); // add the fragment's nodes to the body of resulting document Iterator<Element> nodes = fragment.children().iterator(); while ( nodes.hasNext() ) { document.body().appendChild( nodes.next() ); } return document; } }
public static JXDocument createByUrl(String url){ Elements els; try { els = Jsoup.connect(url).get().children(); } catch (Exception e) { throw new XpathParserException("url资源获取失败",e); } return new JXDocument(els); }
private static Document convert(org.jsoup.nodes.Document document) { Document w3cDoc = new org.apache.html.dom.HTMLDocumentImpl(); org.jsoup.nodes.Element rootEl = document.children().first(); if (rootEl != null) { NodeTraversor.traverse(new DocumentConverter(w3cDoc), rootEl); } return w3cDoc; }
public static JXDocument createByUrl(String url){ Elements els; try { els = Jsoup.connect(url).get().children(); } catch (Exception e) { throw new XpathParserException("url资源获取失败",e); } return new JXDocument(els); }
interface DocumentHandler { void process(Document d); } class ExportToPdf implements DocumentHandler { ... } class AppendToParentPdf implements DocumentHandler { ... } // Now you're just passing the interface whose implementation does something with the document void handleDocument(DocumentHandler parentHandler, DocumentHandler childHandler) { for(Document parent : documents) { parentHandler.process(parent); for(Document child : parent.children()) { childHandler.process(child); } } } DocumentHandler appendToParent = new AppendToParentPdf(); DocumentHandler exportToPdf = new ExportToPdf(); // pass the child/parent handlers as needed handleDocument(exportToPdf, appendToParent); handleDocument(exportToPdf, exportToPdf);
if (doc == null || doc.children().size() == 0) { return episodes;
if (doc == null || doc.children().size() == 0) { return md;
if (doc == null || doc.children().size() == 0) { return md;