我已经使用stringbuilder很长一段时间了,以前从来没有出现过这个问题。在本例中,我使用字符串构建器将一个冗长的XML块组合在一起,最后将其放入一个字符串中以提交给一个web服务。在ToString中,所有的双引号都会转换为双引号。
Dim tXML As New StringBuilder
Dim tt As String
tXML.Append("<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "UTF-8" & """" & "?>")
tt = tXML.ToString
'At this point the value of tXML is what I'd expect:
{<?xml version="1.0" encoding="UTF-8"?>}
'However the value of tt is
"<?xml version=""1.0"" encoding=""UTF-8""?>"
'this method of double-quotes produces the same result
tXML.Append("<?xml version=""1.0"" encoding=""UTF-8""?>")这应该很简单,但我感到困惑。谢谢。
发布于 2016-07-06 22:58:18
使用StringBuilder组装Xml似乎不是最好的方法。为什么不将Xml类与VB.Net的XML文本一起使用呢?
Imports System.Xml.Linq
Private Sub createXml()
Dim xDoc As New XDocument()
xDoc.Declaration = New XDeclaration("1.0", "utf-8", "yes")
xDoc.Add(<Root attr="x">
<SomeElement>Some Value</SomeElement>
</Root>)
xDoc.Save("c:\somefolder\myfile.xml")
End Subhttps://stackoverflow.com/questions/38209359
复制相似问题