我正在阅读一个XML文件,我想将实际内容写入HTML。我认为问题在于HtmlTextWriter将我的XML标签视为HTML标签。我曾尝试使用HttpUtility.HtmlEncode/Decode和SecurityElement.Escape,但这些都不起作用。如何转义标签以便我可以将字符串写入我的HTML页面。c#:转义XML字符串并写入HTML
private string WriteXmlToHtml()
{
StringWriter stringWriter = new StringWriter();
using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
{
int counter = 0;
string line;
StreamReader file = new StreamReader("test.xml");
while ((line = file.ReadLine()) != null)
{
//HttpUtility.HtmlDecode(line);
//System.Security.SecurityElement.Escape
writer.Write(line);
counter++;
}
}
return stringWriter.ToString();
}
感谢。但我想我实际上把它放在一个2列的HTML表格上。第一列将是行号,第二列将包含标签。你有什么想法如何保存XML的缩进? – jmc 2015-02-24 12:30:37
@wintersolstice你可以使用
标签,并将其放入xml中。 – xanatos 2015-02-24 12:35:53@xanatos虐待它试一试。但你能告诉我吗? – jmc 2015-02-24 14:02:05