简体   繁体   中英

AngleSharp and XHTML round-trip

I'm trying to parse an XHTML file using AngleSharp, make a change, then output it. However, I'm having some issues getting the output to match the input.

  • If I use the XML parser and either the XMLMarkupFormatter or the HtmlMarkupFormatter I get no self-closing tags (all are <img></img> ) and no XML declaration.

  • If I use the HTML parser and the HTMLMarkupFormatter I get XML invalid self-closing tags (all are simply <img> ) and no XML declaration.

  • If I use the HTML parser and the XMLMarkupFormatter I get nice self closing tags ( <img /> ), and the XML declaration - however, the XML declaration is picked up as a comment and outputted as <!-- <?xml version="1.0" encoding="UTF-8"?> -->

Is there a way around this or do I need to write my own MarkupFormatter ?

Simple answer: It sounds like you need to provide your own MarkupFormatter .

There has been some effort to come up with an XhtmlMarkupFormatter , but this component has unfortunately not been realized so far. I imagine such a component may combine the serialization from both, the existing HTML and the available XML formatter.

Maybe this issue on the AngleSharp repo helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM