CsQuery icon indicating copy to clipboard operation
CsQuery copied to clipboard

Working with XHTML

Open cmwoods opened this issue 11 years ago • 4 comments

Is there any way to specify that the Save or Render methods should generate XHTML output? I'm reading in XHTML input document but the output is generated is no longer XHTML (tags like meta aren't being self-closed which I think is a requirement of XHTML?).

cmwoods avatar Mar 20 '13 22:03 cmwoods

Also the BR tag seems to get rendered without it's self closing slash, which breaks XHTML compliance.

Req avatar Apr 08 '13 14:04 Req

I'm just getting back into the swing of things after my daughter was born (:first-child) but I'm planning to get caught up this week! Thanks for hanging in there.

jamietre avatar Apr 08 '13 14:04 jamietre

+1

This sounds (no harm intended) like a small change?

304NotModified avatar Nov 26 '14 15:11 304NotModified

This works as far as I can tell, see CsQuery.Tests\HtmlParser\DocType.cs - as long as the document type is XHTML, it should render the correct tag format.

    [Test]
    public void Issue94()
    {
        string html = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN""      
             ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
            <html><head></head><body><br></body></html>";
        var dom = CQ.Create(html);
        var br = dom["br"];
        Assert.AreEqual(br.RenderSelection(), "<br />");
    }

You can change the doctype by replacing the DocType node:

dom.Document.DocTypeNode = dom.Document.CreateDocumentType(DocType.XHTML);

jamietre avatar Nov 26 '14 15:11 jamietre