xml格式 [英] xml format

查看:58
本文介绍了xml格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我正在以XML格式保存数据但是我遇到了使格式正确的问题。

I'm working on an app an i'm saving the data in an XML format but i'm having issues with getting the format correct.

输出看起来像这样

< GasInfoEntries>

  < Gallons> 123< / Gallons>

  <价格> 456< /价格>

< / GasInfoEntries>< GasInfoEntries>

  < Gallons> 123< / Gallons>

  <价格> 456< /价格>

< / GasInfoEntries>

<GasInfoEntries>
  <Gallons>123</Gallons>
  <Price>456</Price>
</GasInfoEntries><GasInfoEntries>
  <Gallons>123</Gallons>
  <Price>456</Price>
</GasInfoEntries>

我用它来写它

List<GasInfoEntries> data = new List<GasInfoEntries>();

                        data.Add(new GasInfoEntries() { Gallons = TxtBoxGas.Text, Price = TxtBoxPrice.Text });
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteStartElement("GasInfoEntries");

                        xmlWriter.WriteStartElement("Gallons", "");
                        xmlWriter.WriteString(TxtBoxGas.Text);
                        xmlWriter.WriteEndElement();
                    

                        xmlWriter.WriteStartElement("Price", "");
                        xmlWriter.WriteString(TxtBoxPrice.Text);
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();
                        //do i need?
                        xmlWriter.Close();

我收到此错误

任何想法?

谢谢

推荐答案

你应该去返回并阅读有关XML格式的信息。 你没有root对象。

You should go back and read about the XML format.  You have no root object.

< root>

<root>

这里的东西

< / root> ;

</root>

Root可以是您想要的任何名称。

Root can be whatever name you want.


这篇关于xml格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆