@Test public void testHtmlAndXmlSyntax() { String h = "<!DOCTYPE html><body><img async checked='checked' src='&<>\"'><>&"<foo />bar"; Document doc = Jsoup.parse(h); doc.outputSettings().syntax(Syntax.html); assertEquals("<!doctype html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async checked src=\"&<>"\"><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); assertEquals("<!DOCTYPE html>\n" + "<html>\n" + " <head></head>\n" + " <body>\n" + " <img async=\"\" checked=\"checked\" src=\"&<>"\" /><>&\"\n" + " <foo />bar\n" + " </body>\n" + "</html>", doc.html()); }
@Override void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { if (out.syntax() == Syntax.html && !has(PUBLIC_ID) && !has(SYSTEM_ID)) { // looks like a html5 doctype, go lowercase for aesthetics accum.append("<!doctype"); } else { accum.append("<!DOCTYPE"); } if (has(NAME)) accum.append(" ").append(attr(NAME)); if (has(PUB_SYS_KEY)) accum.append(" ").append(attr(PUB_SYS_KEY)); if (has(PUBLIC_ID)) accum.append(" \"").append(attr(PUBLIC_ID)).append('"'); if (has(SYSTEM_ID)) accum.append(" \"").append(attr(SYSTEM_ID)).append('"'); accum.append('>'); }
private Document createXmlDocument(String version, String charset, boolean addDecl) { final Document doc = new Document(""); doc.appendElement("root").text("node"); doc.outputSettings().syntax(Syntax.xml); if( addDecl == true ) { XmlDeclaration decl = new XmlDeclaration("xml", "", false); decl.attr("version", version); decl.attr("encoding", charset); doc.prependChild(decl); } return doc; }
private Document createXmlDocument(String version, String charset, boolean addDecl) { final Document doc = new Document(""); doc.appendElement("root").text("node"); doc.outputSettings().syntax(Syntax.xml); if( addDecl == true ) { XmlDeclaration decl = new XmlDeclaration("xml", false); decl.attr("version", version); decl.attr("encoding", charset); doc.prependChild(decl); } return doc; }
@Test public void htmlParseDefaultsToHtmlOutputSyntax() { Document doc = Jsoup.parse("x"); assertEquals(Syntax.html, doc.outputSettings().syntax()); }
protected void initialiseParse(String input, String baseUri, ParseErrorList errors) { super.initialiseParse(input, baseUri, errors); this.stack.add(this.doc); this.doc.outputSettings().syntax(Syntax.xml); }