使用转义字符来替换 &与 &;在 xml 文件 vb.net 中
我正在尝试替换 &在 xml 文档中的服务名称中。
的&正在导致错误。无论如何,我可以编写一些可以转义“&”的代码吗?作为“&”?
I am trying to replace an & in the name of a service in an xml document.
The & is causing an error. Is there anyway i can write some piece of code which will escape "&" as " & a m p ;"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用
XmlTextWriter
写出您的 XML;它会为你处理转义。代码可能如下所示:
显然,如果要写入流而不是文件,则需要使用 XmlTextWriter 的其他构造函数。
Consider using an
XmlTextWriter
to write out your XML; it will handle the escaping for you.The code might look something like this:
Obviously, if you're writing to a stream rather than a file, you'd need to use the other constructor for the XmlTextWriter.