简体   繁体   中英

encoding HTML issues inside xml tag xmltextwriter

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 "& lt;" " & gt;"

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?

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));

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