Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Nov 15, 2013 11:19 am

Hello,

in our sharepoint application page, we have a richtextbox control, where you can copy-pase word text, and it will translate it into the HTML

The problem that the generated HTML code is not W3C compliant, and has some SPAN included in P, or in I etc.

When I try to insert this genreated html to my Word document, I get a XmlSchemaValidationException. If the code is "clean", the insert works well.

Is there a work around?

Code: Select all
 
  while (nodes.Count > 0)
            {
                ICompositeObject node = nodes.Dequeue();
                foreach (IDocumentObject child in node.ChildObjects)
                {
                    if (child.DocumentObjectType == DocumentObjectType.TextBox)
                    {
                        Spire.Doc.Fields.TextBox txt = child as Spire.Doc.Fields.TextBox;           
                        txt.Body.AddParagraph().AppendHTML([b]MyHtml[/b])
.......................


1) Utilisateur: 0#.w|ogf\administrator
2) Url: http://frvmspappdev1/Pages/CreationAvis ... sDecesID=7
3) Message: System.Xml.Schema.XmlSchemaValidationException: The element 'i' in namespace 'http://www.w3.org/1999/xhtml' has invalid child element 'div' in namespace 'http://www.w3.org/1999/xhtml'. List of possible elements expected: 'http://www.w3.org/1999/xhtml:a http://www.w3.org/1999/xhtml:br http://www.w3.org/1999/xhtml:span http://www.w3.org/1999/xhtml:bdo http://www.w3.org/1999/xhtml:object http://www.w3.org/1999/xhtml:applet http://www.w3.org/1999/xhtml:img http://www.w3.org/1999/xhtml:map http://www.w3.org/1999/xhtml:iframe http://www.w3.org/1999/xhtml:tt http://www.w3.org/1999/xhtml:i http://www.w3.org/1999/xhtml:b http://www.w3.org/1999/xhtml:u http://www.w3.org/1999/xhtml:s http://www.w3.org/1999/xhtml:strike http://www.w3.org/1999/xhtml:big http://www.w3.org/1999/xhtml:small http://www.w3.org/1999/xhtml:font http://www.w3.org/1999/xhtml:basefont http://www.w3.org/1999/xhtml:em http://www.w3.org/1999/xhtml:strong http://www.w3.org/1999/xhtml:dfn http://www.w3.org/1999/xhtml:code http://www.w3.org/1999/xhtml:q http://www.w3.org/1999/xhtml:samp http://www.w3.org/1999/xhtml:kbd http://www.w3.org/1999/xhtml:var http://www.w3.org/1999/xhtml:cite http://www.w3.org/1999/xhtml:abbr http://www.w3.org/1999/xhtml:acronym http://www.w3....
at System.Xml.XmlValidatingReaderImpl.InternalValidationCallback(Object sender, ValidationEventArgs e)
at System.Xml.Schema.XsdValidator.ValidateChildElement()
at System.Xml.Schema.XsdValidator.ValidateElement()
at System.Xml.Schema.XsdValidator.Validate()
at System.Xml.XmlValidatingReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlDocument.Load(XmlReader reader)
at spr₵.ᜀ(String A_0, XmlSchema A_1)
at spr₵.ᜈ(String A_0)
at spr₵.ᜀ(IBody A_0, String A_1, Int32 A_2, Int32 A_3)
at spr₵.ᜀ(IBody A_0, String A_1, Int32 A_2, Int32 A_3, IParagraphStyle A_4, ListStyle A_5)
at Spire.Doc.Documents.Paragraph.AppendHTML(String html)
at OGF.AvisDeces.Components.Presenters.AvisDecesCreationPresenter.InsertText(IDocument document, String body1)
at OGF.AvisDeces.Components.Presenters.AvisDecesCreationPresenter.GenerateDocument()

Pierrers
 
Posts: 8
Joined: Wed Nov 13, 2013 2:59 pm

Mon Nov 18, 2013 5:59 am

Hello,

Sorry for late reply as weekend.

Could you please provide us your Html code if convenience? It would be helpful to investigate the issue.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Nov 18, 2013 9:00 am

This is one of the samlples. But the problem occurs with basically any word document saved as HTML, as long it is a little bit formatted

Had to upload zipped file, otherwise forum did not allow

Pierrers
 
Posts: 8
Joined: Wed Nov 13, 2013 2:59 pm

Tue Nov 19, 2013 6:43 am

Hello,

Thanks for your information.
We tested your html document with the following method, it works fine, please add that line and try it again.
Code: Select all
 
Document doc = new Document();
doc.XHTMLValidateOption = XHTMLValidationType.None;//please add this line
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();
string htmlstr = File.ReadAllText(@"..\..\testhtml.html");
para.AppendHTML(htmlstr);
doc.SaveToFile(@"..\..\result.docx",FileFormat.Docx);

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Nov 22, 2013 9:14 am

Hello,

Has the issue been resolved? Could you please give us some feedback if convenience?

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc