【发布时间】:2019-03-07 10:52:12
【问题描述】:
我正在尝试仅使用“UTF-8”编码生成 XML 消息:
Dim doc As System.Xml.XmlDataDocument = New System.Xml.XmlDataDocument(ds)
Dim n1 As System.Xml.XmlNode = doc.FirstChild
Dim doc2 As System.Xml.XmlDocument = New System.Xml.XmlDocument
doc2.LoadXml(n1.FirstChild.OuterXml)
doc2.InsertBefore(doc2.CreateXmlDeclaration("1.0", "utf-8", "yes"), doc2.FirstChild)
doc2.Save(outFile)
但是,每次生成文件时,编码都会列为“UTF-8 签名”。我尝试使用以下内容从消息中删除前三个字符:
def xmlbytes = outFile.toString().getBytes().flatten()
xmlbytes.remove(0)
xmlbytes.remove(0)
xmlbytes.remove(0)
也失败了。
是否有更有效的方法来确保编码仅保留为“UTF-8”?
我没有使用 xDocument,因此我无法从其他线程应用解决方案。
【问题讨论】:
标签: xml visual-studio-2010 vb.net-2010