将数据集保存为 XML 可以覆盖生成的标签名称以获得更小的 XML
因此,我将数据集保存到应用程序中的 xml 文件中,在该应用程序中生成较小的文件很重要。现在,它只是将 XML 元素保存为数据集表和字段的名称。我想知道是否有一种方法可以轻松地将这些标签保存为默认数据集名称之外的其他内容,并使用相同的名称将它们加载回来。
例如,现在我将执行类似的操作来保存数据集
XmlTextWriter xml = new XmlTextWriter("myfile.xml", Encoding.UTF8) { Formatting = Formatting.None };
myDataset.WriteXml(xml);
,它将生成如下所示的长 xml...
<MYDataSet xmlns="http://tempuri.org/MYDataSet.xsd">
<MyElement><ReallyLongTagNames>other info and tags</ReallyLongTagNames></MyElement>
...
</MyDataSet>
我希望能够保存和加载看起来更像这样的内容以节省空间,但我找不到好的方法来做到这一点。很好的意义,让我的数据集不那么神秘,但仍然能够像这样加载和保存 XML。
<MYDataSet xmlns="http://tempuri.org/MYDataSet.xsd">
<a><b>other info and tags</b></a>
...
</MyDataSet>
保存数据集时有没有一种好的方法可以让 xml 以这种方式打印出来?
So I'm saving out a dataset to an xml file in an application where producing a smaller file is important. Right now it just saves the XML elements as the name of the datasets tables and fields. I'm wondering if instead there's a way to easily save out these tags as something other than the default dataset names and load them back in using the same names.
For example right now I'll do something like this to save out the dataset
XmlTextWriter xml = new XmlTextWriter("myfile.xml", Encoding.UTF8) { Formatting = Formatting.None };
myDataset.WriteXml(xml);
and it'll produce long xml that looks like this...
<MYDataSet xmlns="http://tempuri.org/MYDataSet.xsd">
<MyElement><ReallyLongTagNames>other info and tags</ReallyLongTagNames></MyElement>
...
</MyDataSet>
I want to be able to save and load stuff that looks more like this to conserve space but I can't find a good way to do it. Good meaning keeping my dataset from being cryptic but still being able to load and save out XML like this.
<MYDataSet xmlns="http://tempuri.org/MYDataSet.xsd">
<a><b>other info and tags</b></a>
...
</MyDataSet>
Is there a good way to get xml to print out this way when saving off a dataset?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在导出到 XML 之前重命名 DataSet 中的列怎么样?
How about renaming the columns in the DataSet before exporting to XML?
如果文件大小很重要,则使用二进制格式化程序。这将大大减小尺寸。
If file size is important then use the Binary Formatter. This will reduce the size dramatically.