如何使 XmlSerialiser 不以 开头?
我正在使用的文件格式 (OFX) 是类似 XML 的,并且在类似 XML 的位开始之前包含一堆纯文本内容。但它不喜欢在纯文本和 XML 部分之间存在,所以我想知道是否有办法让 XmlSerialiser 忽略它。我知道我可以浏览该文件并删除该行,但一开始就不写它会更简单、更干净!有什么想法吗?
The file format I'm working with (OFX) is XML-like and contains a bunch of plain-text stuff before the XML-like bit begins. It doesn't like having between the plain-text and XML parts though, so I'm wondering if there's a way to get XmlSerialiser to ignore that. I know I could go through the file and wipe out that line but it would be simpler and cleaner to not write it in the first place! Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须操作在调用
序列化
方法。其Settings
属性具有OmitXmlDeclaration
属性,您需要将其设置为 true。您还需要设置ConformanceLevel
属性,否则 XmlWriter 将忽略OmitXmlDeclaration
属性。You'll have to manipulate the XML writer object you use when calling the
Serialize
method. ItsSettings
property has aOmitXmlDeclaration
property, which you'll want to set to true. You'll also need to set theConformanceLevel
property, otherwise the XmlWriter will ignore theOmitXmlDeclaration
property.不太难,您只需序列化到显式声明的 XmlWriter 并在序列化之前设置该编写器的选项即可。
Not too tough, you just have to serialize to an explicitly declared XmlWriter and set the options on that writer before you serialize.