In HTML5, <br> is preferred over <br/>.
We use the same html to display on a page, and within a Word document created with DoCIO. However. the
paragraph.AppendHTML() method only supports xhtml.
I think it is time that the HTML format is updated to Html5.
|
//Loads the template document
WordDocument document = new WordDocument();
document.EnsureMinimal();
//Html string to be inserted
string htmlstring = "<br> is preferred over </br>";
//Validates the Html string
bool isValidHtml = document.LastSection.Body.IsValidXHTML(htmlstring, XHTMLValidationType.None); |
Hi Lokesh,
thank you. I understand how it works. However, according to the HTML specs <br> is preferred. So my remark is merely a suggestion to consider changing your approach, so that valid HTML5 is supported. There are many packages available that can do this.
Best regards,
Pieter
I also find this a bit odd, since the method name is AppendHtml (and not append AppendXml) so I think it
be good to accept valid Html :)
Hi Artur,
In Word library (DocIO) we use XmlReader
for parsing the content from input HTML. So, the input HTML should meet XML
standard (have proper open and close tags), even if you specify XHTMLValidationType
parameter as XHTMLValidationType.None.
Therefore, Essential DocIO supports only XHTML 1.0 standard for the HTML. We
internally perform the XHTML 1.0 validation for the input HTML in DocIO and then
process the document further. If the input HTML fails to meet the XHTML 1.0
complaints then exception will be thrown with respect the unsupported elements.
Please refer our UG documentation to know more details about this,
https://help.syncfusion.com/file-formats/docio/html
Regards,
Suriya Balamurugan.
Just a noteI am using the Syncfusion Rich text editor in ASP.Net Core which adds <br> tags but it seems like the DocIO library won't accept it, it would be create if the products could be aligned.
|
using (WordDocument document = new WordDocument()) { document.EnsureMinimal(); // Define a string containing HTML with a line break tag string htmlstring = "You can use the <br> tag to add line breaks wherever needed."; // Append the HTML string to the last paragraph of the document document.LastParagraph.AppendHTML(htmlstring);
using (FileStream fileStreamOutput = File.Create(@"C:\HTML-br-tag.docx")) { document.Save(fileStreamOutput, FormatType.Docx); } } |
Kindly refer to the documentation to perform Word to HTML and HTML to Word
Conversions
Convert Word to HTML and vice versa in C# | Syncfusion
Regards,
Dharanya.