gpt4 book ai didi

.net - 序列化对象时,在.Net中设置StandAlone = Yes

转载 作者:行者123 更新时间:2023-12-03 20:15:44 24 4
gpt4 key购买 nike

在下面的代码中,我要将XML设置为“standalone = yes”,我该怎么做?

Dim settings As New Xml.XmlWriterSettings
settings.Encoding = encoding

Using stream As New IO.MemoryStream, xtWriter As Xml.XmlWriter = _
Xml.XmlWriter.Create(stream, settings)
serializer.Serialize(xtWriter, obj)
Return encoding.GetString(stream.ToArray())
End Using

例如,我有这个:
<?xml version="1.0" encoding="utf-8"?>

但是我想要这个:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>

最佳答案

如果要执行此操作,则需要使用 WriteProcessingInstruction 方法并手动将其写出。

    Using stream As New IO.MemoryStream, xtWriter As Xml.XmlWriter = Xml.XmlWriter.Create(stream, settings)
xtWriter.WriteProcessingInstruction("xml", "version=""1.0"" encoding=""UTF-8"" standalone=""yes""")
serializer.Serialize(xtWriter, obj)
Return encoding.GetString(stream.ToArray())
End Using

关于.net - 序列化对象时,在.Net中设置StandAlone = Yes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6997067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com