使用 XmlWriter 编写格式化的 XML
我正在尝试将 XML 文件写入独立存储,但我想将其格式化为:-
<SampleData>
<Item Property1="AliquaXX" />
<Item Property1="Integer" />
<Item Property1="Quisque" />
<Item Property1="Aenean" />
<Item Property1="Mauris" />
<Item Property1="Vivamus" />
<Item Property1="Nullam" />
<Item Property1="Nam" />
<Item Property1="Sed" />
<Item Property1="Class" />
</SampleData>
但如果我能解决这个问题,我很困惑,有人可以帮忙吗?
I'm trying to write to an XML file to the isolated storage but I would like to format it like this:-
<SampleData>
<Item Property1="AliquaXX" />
<Item Property1="Integer" />
<Item Property1="Quisque" />
<Item Property1="Aenean" />
<Item Property1="Mauris" />
<Item Property1="Vivamus" />
<Item Property1="Nullam" />
<Item Property1="Nam" />
<Item Property1="Sed" />
<Item Property1="Class" />
</SampleData>
but I'm buggered if I can work it out, can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我怀疑您需要创建一个
XmlWriterSettings
具有您想要的行为(缩进等),然后在创建时将其传递给XmlWriter
。只需设置缩进
为 true 可能就足够了:I suspect you need to create an
XmlWriterSettings
with the behaviour you want (indentation etc) and then pass that to theXmlWriter
on creation. Just settingIndent
to true may well be enough:您可以通过 XmlWriterSettings 自定义 xml 输出。
您没有包含任何代码,但您可以在创建 XmlWriter 时设置 XmlWriterSettings。您也可以使用类似的东西:
You can customize the xml output via the XmlWriterSettings.
You didn't include any code, but you can set the XmlWriterSettings when you create the XmlWriter. You can also just use something like:
如果像我一样,您正在实现自己的
XmlWriter
,您可以执行以下操作:或在其构造函数中执行
this.Formatting = Formatting.Indented
。If, like me, you're implementing your own
XmlWriter
you can do:or do
this.Formatting = Formatting.Indented
in it's constructor.您可以使用 DataSet.GetXML()
它与 XmlWriter 无关,但您可以使用它来格式化 XML。
You can use
DataSet.GetXML()
It is not related to XmlWriter but you can use it for formatting XML.