encoding HTML issues inside xml tag xmltextwriter

153 views Asked by At

I'm dynamically creating, populating and submitting an infopath form to a SharePoint form library, I'm using the XMLTextWriter to create the xml for the infopath, just like this post:

http://www.codeproject.com/Articles/570032/Dynamically-Create-Populate-and-Submit-an-InfoPath

The problem i'm having is when i try to include html in the content of the tag, the xmltextwriter treats all the html <> tags as "& l t;" " & g t;"

XmlTxWriter.WriteStartElement("my", "TradeTicket", FormNamespace_my);
XmlTxWriter.WriteAttributeString("xmlns", "xsi", null, FormNamespace_xsi);
XmlTxWriter.WriteString("<html><head></head><body><table><tr><td>test content</td></tr></table></body></html>");
XmlTxWriter.WriteEndElement();
XmlTxWriter.WriteEndElement();

I've tried using XmlTxWriter.WriteRaw but that didn't work either. Is there anything else i can use?

1

There are 1 answers

0
depoip On

Use WebUtility.HtmlDecode

for example:

StringWriter sb = new StringWriter();

XmlTextWriter XmlTxWriter = new XmlTextWriter(sb);

.. your write code ..

writer.Flush();

File.WriteAllText("your file", WebUtility.HtmlDecode(sb.ToString));