没有& lt;输出? [英] Not Having The < Output?

查看:75
本文介绍了没有& lt;输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用StringBuilder构建一个xml文档,后来与flash movice一起使用以提供FlashVars。我遇到的问题是每当放到标准输出时的值,在这种情况下,在webform上运行的flash电影会丢失
编码。它有& lt;当我需要"<"时,字符在整个字符串中被替换。所以像这样:

I am building an xml document using a StringBuilder that is later used in conjunction with a flash movice to provide FlashVars. The problem I am running into is the value whenever put to standard output, in this case a flash movie running on a webform the encoding appears lost. It has the &lt; character replaced throughout the string, when I need the "<". So like this:

FlashVars ="& lt; root>& lt; UTCOffset> 240& lt; / UTCOffset>& lt; guid>

FlashVars="&lt;root>&lt;UTCOffset>240&lt;/UTCOffset>&lt;guid>

有没有办法让StringBuilder用转义的等价物替换字符?

Is there a way to not have the StringBuilder replace the characters with their escaped equivalent?

推荐答案

请不要使用StringBuilder来构造XML。您将遇到各种问题,上面是一个例子。

Please don't use StringBuilder to construct XML. You will run into all kinds of issues, the above being one example.

而是使用XmlWriter(通过XmlWriter.Create创建)或某些更高级别的API,如XmlDocument或XDocument。 XmlWriter API将负责转义字符,以便生成的XML格式正确并包含您需要的值。

Instead use XmlWriter (created through XmlWriter.Create) or some higher level API like XmlDocument or XDocument. The XmlWriter API will take care of escaping the characters such that the produced XML is well formed and contains the values you need.

请注意,'<'字符不允许出现在里面属性的值,这就是它需要被& lt;替换的原因。

Note that the '<' character is not allowed to appear inside the value of an attribute, that's why it needs to be replaced by &lt;.

谢谢,


这篇关于没有&amp; lt;输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆