摘要:[分享] 產生XML如何關掉 Utf-8 的 BOM 標頭
Dim xml As XElement = New XElement("option", New XElement("request", _
New XAttribute("userid", _strUserId), _
New XAttribute("username", _strUserName), _
New XAttribute("email", _strUserEmail), _
New XAttribute("password", _strUserPwd), _
New XAttribute("diskquota", _strdiskquota), _
New XAttribute("maxoutconnection", _strmaxoutconnection) _
, "adduser" _
) _
)
Dim objTextWriter As TextWriter
objTextWriter = New StreamWriter("My.XML")
Dim objXmlWriterSettings As New XmlWriterSettings
'Turn off Byte Order Mark (BOM)
objXmlWriterSettings.Encoding = New UTF8Encoding(False)
Using objXmlWriter As XmlWriter = XmlWriter.Create(objTextWriter, objXmlWriterSettings)
xml.WriteTo(objXmlWriter)
objXmlWriter.Flush()
End Using
若要用BOM標頭,改成如下
objXmlWriterSettings.Encoding = System.Text.Encoding.UTF8
