在C#中的特殊格式的XML文件 [英] Create XML file in C# in special format

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

问题描述

我想用这种格式的C#创建一个XML文件

您可以可以我?

我有一个文件,我想创建这种格式的文件。但我不知道与该类别在C#中的我能做到这一点。

 <表>
    < independentVar>航空/ h_b-MAC-FT< / independentVar>
    < tableData>
          0 1.229
          0.1 1.124
          0.15 1.116
          0.2 1.124
          0.3 1.105
          0.4 1.041
          0.5 1.034
          0.6 1.019
          0.7 1.008
          0.8 1.003
          0.9 1.001
          1 1
          1.1 1
    < / tableData>
< /表>
 

解决方案

在C#中有三个最常用的类来创建XML:

  1. 的XmlWriter
  2. 的XmlDocument
  3. 的XDocument

这是很难给你不知道你的任务的情况下提出建议。

在你的examlpe还有一个挑战是preserve空格。默认XML设置修剪/忽略whitepaces和换行,除非你指定XML元素在某些特殊的属性(参见:的 msdn.microsoft.com/en-us/library/ms256097.aspx )。不幸的是一些应用程序/读者忽略它呢。

如果你必须阅读你的XML用自己的code,你可以配置你的读者,以preserve whitepaces在任何情况下。请参阅: msdn.microsoft.com/en-us/library/bb387014.aspx

I want create a xml file using C# in this format

Can you can me?

I have one file and i want to create a file with this format. But I don't know with which of the classes in C# I can do it.

<table>
    <independentVar>aero/h_b-mac-ft</independentVar>
    <tableData>
          0             1.229       
          0.1           1.124       
          0.15          1.116       
          0.2           1.124       
          0.3           1.105       
          0.4           1.041       
          0.5           1.034       
          0.6           1.019       
          0.7           1.008       
          0.8           1.003       
          0.9           1.001       
          1             1           
          1.1           1 
    </tableData>
</table>

解决方案

In c# there are three most used classes to create XML:

  1. XmlWriter
  2. XmlDocument
  3. XDocument

It is difficult to give you a recommendation without knowing the context of your task.

One more challenge in your examlpe is to preserve whitespaces. Default XML settings trim / ignore whitepaces and line feeds, unless you specify some special attribute on XML element (See: msdn.microsoft.com/en-us/library/ms256097.aspx). Unfortunately some applications / readers ignore it anyway.

If you must read your xml with your own code you can configure your reader to preserve whitepaces in any case. See: msdn.microsoft.com/en-us/library/bb387014.aspx

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

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